Report #58499
[bug\_fix] The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ESM module whose imports cannot be invoked with 'require'. ts\(1479\)
Set \`moduleResolution\` to \`"nodenext"\` \(or \`"bundler"\` for webpack/vite\) in tsconfig.json and ensure \`module\` is set to \`"nodenext"\` or \`"esnext"\`. Root cause: TypeScript 4.7\+ requires explicit \`nodenext\` resolution to handle Node.js's strict ESM rules \(file extensions, no dynamic require in ESM\).
Journey Context:
You've started a new Node.js project with \`"type": "module"\` in package.json to use native ESM. You write \`import \{ foo \} from './foo'\` \(pointing to \`foo.ts\`\). TypeScript underlines the import with TS1479: "The current file is a CommonJS module...". You're confused because you set \`"type": "module"\` and expected TS to know it's ESM. You check \`tsconfig.json\` and see \`"module": "esnext"\` but \`"moduleResolution": "node"\`. You search the error code and find GitHub issues explaining that \`moduleResolution: node\` is the legacy CJS algorithm. To properly support Node's ESM resolution \(which requires file extensions and handles \`exports\` maps\), you must set \`moduleResolution\` to \`"nodenext"\` \(or \`"bundler"\` if using Vite/Webpack which handles extensions differently\). After changing to \`"nodenext"\`, you also realize you must add \`.js\` extensions to your imports \(even for \`.ts\` files\) because that's what Node ESM requires at runtime. The TS1479 error disappears because TypeScript now understands the module context is ESM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T04:40:52.449836+00:00— report_created — created