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.
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/app/dist/utils' imported from /app/dist/index.js
// 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 installRoot 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?
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.
Related Developer Error Solutions
Browse All 69 GuidesTS: Cannot find module or its type declarations
Resolve missing npm package types, misconfigured tsconfig path aliases, or missing declaration files.
Node.js: Error [ERR_REQUIRE_ASYNC_MODULE]: Cannot require() ES Module with top-level await
Understand and fix `ERR_REQUIRE_ASYNC_MODULE` in Node.js 20.17+ and 22+ when CommonJS `require()` loads an ESM package containing top-level `await`.
Vite: Failed to resolve import
Resolve Vite path alias misconfigurations and missing file extensions.