Skip to main content
TypeScript & Node.js · Developer Error Resolution Lab

Fix Node.js 'Error [ERR_MODULE_NOT_FOUND]: Cannot find module' in ES Modules

Fix ESM import resolution: add .js extensions to relative imports, install missing packages, and align "type": "module" with your TypeScript output.

Triggered Error Message:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/dist/utils' imported from /app/dist/index.js

Customize Solution for Your Environment
// Change:
import x from "./utils";
// To:
import x from "./utils.js";

// tsconfig.json for Node ESM projects
{
  "compilerOptions": {
    "module": "NodeNext",
    "moduleResolution": "NodeNext"
  }
}

# If the missing module is a package, reinstall dependencies:
rm -rf node_modules package-lock.json && npm install

Root Cause & Mechanism Analysis

Why does this error occur?

Native ES modules in Node.js do not guess file extensions or index files. `import './utils'` works in bundlers and CommonJS but fails in ESM, which requires `./utils.js`. The same error appears when a dependency is not installed or `node_modules` is missing in the runtime image.

Frequently Asked Questions

Why .js when my source file is .ts?
TypeScript does not rewrite import paths. The import must match the emitted file name that Node loads at runtime, which is `.js`.
DEVSECOPS & CI/CD PARTNER2 Slots Open

Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?

Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.

Browse All 69 Guides