Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda