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

217
Views
ESM modules, package.json exports, and relative imports within a project

I have a module where the package.json contains:

"type": "module",
"exports": {
  ".": "./build/index.js",
  "./*": "./build/*.js",
  "./sub-dir": "./build/sub-dir/index.js",
  "./sub-dir/*": "./build/sub-dir/*.js"
},

From outside of this package, this now resolves just fine:

const { whatever } = import('module/sub-dir/foo');

however, from within the module, this breaks:

const { whatever } = import('./sub-dir/foo');

This is a TS project, so ./src/sub-dir/foo.ts compiles to ./build/sub-dir/foo.js

So if I change my import to './sub-dir/foo.js', then the built project works, but that path isn't valid in src, so TS breaks.

Any idea on a "proper" configuration here? Or the proper way to import this file, or anything else?

about 4 years ago · Juan Pablo Isaza
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!