Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

221
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda