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

273
Vistas
ERR_MODULE_NOT_FOUND if no .js extension

I have a typescript project where I get the ERROR_MODULE_NOT_FOUND 'path/to/compiled/file' when I try to run my compiled app.js file with node. However, I get rid of this error if I add a .js extension to the import statement in my app.js like this import { function } from "./path/file.js"; How do I get the typescript compiler to automatically add these .js extensions? Alternatively, get node to work without the .js extensions?

My tsconfig.json looks like this:

{
    "compilerOptions": {
        "module": "esnext",
        "target": "es5",
        "noImplicitReturns": true,
        "noUnusedLocals": true,
        "outDir": "dist",
        "sourceMap": true,
        "moduleResolution": "node",
        "esModuleInterop": true,
        "isolatedModules": true,
        "resolveJsonModule": true,
        "typeRoots": ["./src/types", "node_modules/@types"],
        "baseUrl": "./src",
        "paths": {
            "types": ["types"],
            "types/*": ["types/*"],
            "@data/*": ["data/*"],
            "@execute/*": ["execute/*"],
            "@indicators/*": ["indicators/*"],
            "@services/*": ["services/*"],
            "@strategies/*": ["strategies/*"],
            "*": ["node_modules/*"]
        }
    },
    "compileOnSave": true,
    "include": ["src", "test", "dist"],
    "exlude": ["src/types"]
}

My app.ts looks like this:

import { function } from "./path/file";

function();
console.log("test");

export {};
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I was having the exact same issue while trying to setup a new typescript project on node.

What solved it for me at the end was replacing esnext by commonjs on the module option.

I had previously used esnext because of a top-level await, but worked that around by wrapping the await with an async function.

I cannot explain why the compiled javascript imports with esnext does not have the .js extension, or how to tweak the compiler to add this extension for local modules that will also be compiled.

over 4 years ago · Santiago Trujillo Denunciar
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