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

372
Visualizações
TypeScript & NodeJS: Exports is not defined in ES module scope

I have written my NodeJS JavaScript files with Import/Export syntax and my package.json has "type" : "module"

The problem is that after tsc builds the code, the transpiled code in /build/server.js cannot run. It says Exports is not defined in ES module scope

Here's my tsconfig.json

{
  "compilerOptions": {
    "resolveJsonModule": true,
    "incremental": true,
    "target": "es2019" ,
    "module": : "commonjs",
    "allowJs": true ,
    "outDir": "./build",
    "strict": true ,
    "noImplicitAny": false,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true ,
    "alwaysStrict": true ,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true ,
    "inlineSourceMap": true ,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true ,
    "forceConsistentCasingInFileNames": true,
    "useUnknownInCatchVariables": false
  }
}

if I remove "module" : "commonjs" and add "moduleResolution": "Node", I get a different error with my imports:

Cannot find module /build/constants imported from /build/server.js The module /build/constants.js does exist, but in my code I'm not adding .js to my imports, so I'm importing it like this import {CONSTANTS} from 'constants'.

In a TypeScript file, when importing other TypeScript files, should the imports be like import {CONSTANTS} from constants.js or import {CONSTANTS} from constants.ts or import {CONSTANTS} from constants, which is what I have now.

I'm new to TypeScript. What's the best way to solve this problem I'm having?

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I found the solution. "type" : "module" had to be removed from package.json

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