Report #13611
[bug\_fix] Cannot find module './utils' or its corresponding type declarations. TS2307
When using ES Modules in Node.js \(type: 'module'\), TypeScript requires explicit file extensions in import paths. Change the import to include the full relative path with the .js extension: import \{ foo \} from './utils.js'; even if the source file is utils.ts. Also ensure moduleResolution is set to 'NodeNext' or 'Bundler' in tsconfig.json.
Journey Context:
You are migrating your Node.js project to native ES Modules by adding 'type': 'module' to package.json and setting module: 'NodeNext' and moduleResolution: 'NodeNext' in tsconfig.json. Suddenly, all your relative imports like import \{ helper \} from './helper'; are red-underlined with TS2307. You check and the file helper.ts definitely exists. You try adding the .ts extension, but that doesn't work either and feels wrong. You search online and find that for ES Modules, Node.js requires the import to have the exact file extension as it will appear at runtime: .js. You feel counter-intuitive adding .js to import a .ts file, but you change it to import \{ helper \} from './helper.js'; and the error disappears. The TypeScript compiler understands this mapping and outputs the correct .js imports in the compiled code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T19:14:38.825162+00:00— report_created — created