Report #10067
[bug\_fix] TS2835: Relative import paths need explicit file extensions in ECMAScript imports \(or 'Cannot find module' with NodeNext\)
Add the .js extension to all relative import paths in TypeScript source files \(e.g., import \{ foo \} from './utils.js'\), even when targeting .ts files, because TypeScript's NodeNext mode enforces Node.js ESM resolution rules.
Journey Context:
Developer upgrades a project to modern ESM by setting "module": "NodeNext" and "moduleResolution": "NodeNext" in tsconfig.json. Immediately, all relative imports break with errors like "Cannot find module './utils'" or "Relative import paths need explicit file extensions." The developer tries changing imports to './utils.ts' but receives TS2691: "An import path cannot end with a '.ts' extension." Confused, they consult the TypeScript 4.7 release notes documentation. They learn that under NodeNext, TypeScript enforces the same rules as Node.js native ESM: import specifiers must include file extensions, and for TypeScript files, the extension in the source code must be .js \(which TypeScript will then resolve to the .ts file during compilation\). The developer updates all imports to use .js extensions, and both type-checking and Node.js runtime resolution succeed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:46:09.549171+00:00— report_created — created