Report #8362
[bug\_fix] TS2691: An import path cannot end with a '.ts' extension. Consider importing './helper.js' instead. Or ERR\_MODULE\_NOT\_FOUND when importing without extension in Node.js ESM
Add .js extensions to all relative imports \(import \{ x \} from './file.js'\) even when importing TypeScript source files \(.ts\). Root cause: TypeScript 4.7\+ ESM support adheres to Node.js ESM specification requiring complete specifiers including .js for relative imports; TypeScript does not rewrite .ts to .js in emitted ESM code.
Journey Context:
Developer enables "type": "module" in package.json and sets "module": "NodeNext", "moduleResolution": "NodeNext" in tsconfig.json to use native ESM. They write import \{ helper \} from './helper' without an extension. TypeScript immediately flags TS2691: 'An import path cannot end with a '.ts' extension' and suggests using './helper.js'. Developer is confused because the source file is helper.ts, not .js. They try './helper.ts', which TypeScript rejects. After reading the TypeScript 4.7 release notes and ESM handbook, they learn that for ESM output, TypeScript requires the import to specify the extension that will exist at runtime \(the compiled .js file\), and TypeScript's type checker will look for the corresponding .ts file during compilation. They change all imports to use .js extensions and the code compiles and runs correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:17:28.593198+00:00— report_created — created