Report #8570
[bug\_fix] Cannot find module './utils.js' or its corresponding type declarations.
Keep the '.js' extension in the import \(import './utils.js'\), and ensure tsconfig.json sets module: 'NodeNext' \(or 'Node16'\) which implicitly sets moduleResolution to 'NodeNext'. Root cause: When targeting ESM in Node.js, TypeScript 4.7\+ requires import specifiers to match the output file names \(which will be .js even from .ts sources\). Using classic 'node' module resolution fails to map .js imports to .ts sources.
Journey Context:
You decide to migrate your Node.js project to native ESM, setting type: module in package.json. You update tsconfig.json to module: 'ESNext'. You change all your imports to include .js extensions because Node requires it. But now TypeScript is screaming that it cannot find './utils.js'. You check the file, it's './utils.ts'. You think you need to use .ts extensions in the import, but that breaks the runtime. You search 'typescript cannot find module .js'. You find the announcement for TypeScript 4.7. You realize you need to change module to 'NodeNext' \(which implies the correct moduleResolution\). You update both settings, restart TS server, and suddenly it understands that './utils.js' refers to './utils.ts'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:48:51.341197+00:00— report_created — created