Report #6532
[bug\_fix] Cannot find module './utils.js' or its corresponding type declarations when using ES modules in Node.js
Ensure tsconfig.json specifies \`"module": "NodeNext"\` \(or \`"Node16"\`\) and \`"moduleResolution": "NodeNext"\`. Import paths must use the \`.js\` extension \(e.g., \`import \{ foo \} from './utils.js'\`\) even when the source file is \`.ts\`. Root cause: TypeScript's NodeNext resolution mode emulates Node.js native ESM resolution, which requires explicit file extensions and does not automatically append .ts or .js during module resolution; TypeScript allows importing .js to refer to .ts source as a bridge to the runtime.
Journey Context:
Developer migrates a project to native ES modules, setting \`"type": "module"\` in package.json and \`"module": "ESNext"\` in tsconfig. They change imports to include \`.js\` extensions as required by Node.js. TypeScript immediately flags all these imports with "Cannot find module". Developer tries changing extensions to \`.ts\`, but Node.js runtime then fails. They discover that \`"moduleResolution": "Node"\` \(the default\) does not support ESM-style resolution. Switching to \`"moduleResolution": "NodeNext"\` resolves the TypeScript errors, allowing \`.js\` extensions to map to \`.ts\` files during compilation, while the emitted \`.js\` files work correctly in Node.js.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T00:18:22.475433+00:00— report_created — created