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

143
Visualizações
library uses __dirname causing errors in module

So I have a typescript app with type set to module in package.json.

so far everything has worked great, but now after I've imported a google voice api everything breaks when trying to run the app.

> node build --prod

file:///opt/jap/server/build/index.js:132416
    var googleProtoFilesDir = path.join(__dirname, "..", "..", "protos");
                                        ^

ReferenceError: __dirname is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/opt/jap/server/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

Kind of makes sense I guess, but I can't change the type of the app, and the .js file is not something I can control as it is in a dependency.

I've tried adding "types": ["node"] to compilerOptions in tsconfig.json without luck, and I've added "@types/node": "^16.9.1" as a dependency, also without any success.

So is there any obvious solution to this?

also: I do have "esModuleInterop": true in my tsconfig.json

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