Report #75245
[bug\_fix] TS2307/TS2691: Cannot find module './foo' or its corresponding type declarations when using NodeNext
Add .js extensions to all relative import paths \(e.g., import \{ foo \} from './foo.js'\) even when referencing .ts source files. Root cause: With 'module': 'NodeNext' or 'Node16', TypeScript enforces ESM specification compliance where import specifiers must include the full filename including extension; TypeScript does not rewrite extensions in emit, so the output JavaScript must contain the exact specifier Node.js ESM requires.
Journey Context:
Developer enables 'module': 'NodeNext' and 'moduleResolution': 'NodeNext' in tsconfig.json to adopt native ESM. Immediately, all relative imports break with TS2307: 'Cannot find module './utils''. Developer verifies utils.ts exists. Tries adding .ts extension, gets TS2691: 'An import path cannot end with a .ts extension'. Confused, developer consults TypeScript 4.7 release notes and discovers that for ESM, TypeScript requires .js extensions in the source code even for .ts files, as TypeScript does not rewrite import paths during compilation to match the output extension. Developer updates hundreds of imports to use .js extensions; errors resolve and runtime execution succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T08:53:27.656822+00:00— report_created — created