Report #99644
[bug\_fix] The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import\(\)' call instead. ts\(1479\)
Switch \`tsconfig.json\` to \`"module": "NodeNext"\` and \`"moduleResolution": "NodeNext"\`, set \`"type": "module"\` in \`package.json\` \(or rename files to \`.mts\`/\`.cts\`\), and use \`import\`/\`export\` syntax consistently. Avoid mixing \`require\` and \`import\` in the same module.
Journey Context:
You are publishing a TypeScript library for Node 20 and decide to ship ESM. You set \`"module": "ESNext"\` in \`tsconfig.json\` but leave \`moduleResolution\` as \`"node"\`. The build emits \`.js\` files with \`import\` statements, yet in another \`.ts\` file you import an ESM-only dependency and TS1479 appears. You try adding \`"esModuleInterop": true\` and \`"allowSyntheticDefaultImports": true\`, but the error persists because the problem is not default-import shape; it is that the compiler is treating the source file as CJS. You read the error closely: "current file is a CommonJS module". With \`"moduleResolution": "NodeNext"\`, TypeScript reads \`package.json\#type\` and file extensions to decide whether each file is ESM or CJS, matching Node's runtime behavior. You rename the file to \`.mts\` \(or add \`"type": "module"\`\), update \`tsconfig\` to \`"NodeNext"\`, and the import resolves. The fix works because only \`"NodeNext"\` enforces Node's dual-module rules rather than legacy \`"node"\` resolution.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-30T04:48:57.392521+00:00— report_created — created