Report #16884
[bug\_fix] Cannot find module './utils' or its corresponding type declarations. \(TS2307\) when using moduleResolution: NodeNext
Append the explicit \`.js\` extension to the import path in the TypeScript source, even for \`.ts\` files: \`import \{ foo \} from './utils.js'\`. TypeScript's NodeNext resolution maps this to the emitted \`.js\` file. Alternatively, if using \`noEmit\` or \`emitDeclarationOnly\`, enable \`allowImportingTsExtensions: true\` \(requires \`noEmit\`\) to allow \`./utils.ts\`.
Journey Context:
You set \`module: NodeNext\` and \`moduleResolution: NodeNext\` to align with native Node.js ESM. You write \`import \{ helper \} from './helper'\` where \`helper.ts\` exists. TypeScript immediately errors with TS2307. You try \`./helper.ts\`, but TypeScript explicitly forbids \`.ts\` extensions in imports \(prior to 4.7 or without specific flags\). You check that the file exists, check casing \(Linux vs Mac\), all correct. Searching reveals TypeScript 4.7's ESM support requires the import to reflect the output file extension. Since TS compiles \`.ts\` to \`.js\`, you must write \`from './helper.js'\`. You protest that it's a \`.ts\` file, but you try it. TypeScript now resolves it correctly to \`helper.ts\` during type-checking and knows to emit \`helper.js\`. The error is gone.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T03:52:46.563471+00:00— report_created — created