Report #83779
[bug\_fix] Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'nodeNext' or 'bundler'. Did you mean './utils.js'? \(TS2835\)
Add explicit \`.js\` extensions to all relative import paths \(e.g., change \`import \{ foo \} from './utils'\` to \`import \{ foo \} from './utils.js'\`\), even when importing TypeScript files \(the compiler maps \`.js\` to \`.ts\` internally\). For directory imports \(index files\), use the full path including \`/index.js\`.
Journey Context:
Developer is migrating a Node.js library from CommonJS to ESM. They set \`module: "NodeNext"\` and \`moduleResolution: "NodeNext"\` in \`tsconfig.json\` as required for ESM compliance. They change their \`package.json\` to include \`"type": "module"\`. They update their source files to use \`import\`/\`export\` syntax. When they run \`tsc\`, they get TS2835 errors on every relative import: \`Relative import paths need explicit file extensions... Did you mean './utils.js'?\`. The developer is confused because they are writing TypeScript, not JavaScript, and they think they should import \`./utils.ts\` or just \`./utils\`. They try changing it to \`./utils.ts\` but get a different error \(TS2691\) saying an import path cannot end with a \`.ts\` extension. They search and find that TypeScript's \`NodeNext\` mode enforces the Node.js ESM requirement that all imports must include the file extension that will exist at runtime \(\`.js\`\), even though the source is \`.ts\`. The compiler internally maps \`.js\` to \`.ts\` during compilation. The developer updates all imports to include \`.js\` \(e.g., \`import \{ foo \} from './utils.js'\`\), and the errors disappear. They also realize that directory imports like \`import \{ foo \} from './utils'\` \(where \`utils/index.ts\` exists\) are forbidden in ESM and must be written as \`import \{ foo \} from './utils/index.js'\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:12:36.240852+00:00— report_created — created