Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Importing something without evaluating the dependencies

Consider the following file:

/** myFile.ts **/

import something from 'something';
/** ... other imports here ... **/

export enum statuses = {
  100 = "ok"
  200 = "false"
};

export default class Model {
   ....
}

This is a dummy ORM model, which is used on the back-end. Now, what I would like to achieve, is to use part of it (specifically the enum from it) on the front-end also (which has a completely separate code base, with it's own node_modules and dependencies) but if I try to import the enum from this file, the something plugin dependencies is also being evaluated and imported, and my code fails, as that dependency is not part of the front-end codes dependencies.

Is there any way to perform an import on a javascript file, WITHOUT evaluating the dependencies and other part of the code? (with the known risk, that it may fail, if I try to import something that would need those dependencies)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For JavaScript, the answer is "no," and I'm 99% sure that's true for when TypeScript is handling the imports as well.

But it's easy to fix: Put the enum in its own module:

statuses.ts:

export enum statuses = {
  100 = "ok"
  200 = "false"
};

The other project can import from that, rather than from myFile.ts.

If you want, you make it so you don't have to update the code that does use myFile.ts to use that separate module, by re-exporting it in myFile.ts:

export { statuses } from "./path/to/statuses.js";

Or if you need to use statuses in myFile.ts (which you can't with the above):

import { statuses } from "./path/to/statuses.js";
export { statuses };

Either way, code that was doing import Modal, { statuses } from "./myFile.js" keeps working.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!