Report #45814
[bug\_fix] Error \[ERR\_MODULE\_NOT\_FOUND\]: Cannot find module '/project/src/utils' imported from /project/src/index.js
Add the \`.js\` extension to the import path: change \`import \{ util \} from './utils'\` to \`import \{ util \} from './utils.js'\`. For TypeScript, keep the \`.js\` extension in the source code even though the source file is \`.ts\` - the TypeScript compiler does not rewrite specifiers. Root cause: ES Module resolution in Node.js requires complete specifiers including file extensions. Unlike CommonJS, which automatically appends \`.js\`, \`.json\`, or \`.node\`, ESM follows browser-like resolution where the import specifier must be a valid URL or file path.
Journey Context:
You migrate your TypeScript project from CommonJS to ESM by setting \`"type": "module"\` in package.json and \`"module": "ES2020"\` in tsconfig.json. You compile with \`tsc\` and run \`node dist/index.js\`. Immediately you get ERR\_MODULE\_NOT\_FOUND pointing to an import from './utils'. You check and \`dist/utils.js\` definitely exists right next to \`index.js\`. You check your import statement: \`import \{ helper \} from './utils';\`. You assume TypeScript would handle the extension since it resolves modules during compilation, but you read the TypeScript documentation and find that TS intentionally does not rewrite module specifiers - what you write is what gets emitted. You then check the Node.js ESM documentation and realize that unlike CommonJS \(\`require\(\)\`\), ES modules require full file paths including extensions \(browser-style resolution\). You update all your TypeScript source files to include \`.js\` extensions on all relative imports \(e.g., \`from './utils.js'\`\), even though the source files are \`.ts\`. You recompile, run Node, and the application starts successfully without module resolution errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T07:22:32.457600+00:00— report_created — created