Report #60797
[bug\_fix] Cannot find module './utils.js' or its corresponding type declarations. TS2307
Set "moduleResolution": "bundler" \(or "nodenext" for strict Node ESM\) and "module": "ESNext" in tsconfig.json compilerOptions.
Journey Context:
The developer migrates a Node.js project to ESM by setting "type": "module" in package.json. Following Node.js ESM requirements, they add .js extensions to all relative imports: \`import \{ foo \} from './utils.js'\`. TypeScript immediately flags these imports with "Cannot find module './utils.js'". The developer tries changing extensions back to .ts, which breaks Node.js runtime. They try "allowJs": true, which doesn't resolve the resolution error. Researching TypeScript 4.7\+ features, they discover that the default "moduleResolution": "node" strategy expects to resolve ./utils.js to a literal .js file or a directory with an index, not to a .ts source file with a .js specifier. The "bundler" mode \(or "nodenext"\) specifically supports the extension rewriting and resolution rules required for ESM where .js specifiers map to .ts sources.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:31:56.127158+00:00— report_created — created