Report #17027
[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 to allow the module to be loaded asynchronously. ts\(1479\)
Rename the consuming file to use the \`.mts\` extension \(to force ESM\) if it should be ESM, or rename the target dependency file to use \`.cts\` \(to force CommonJS\) if it should be CJS. Alternatively, convert the import to a dynamic \`import\(\)\` call wrapped in an async function.
Journey Context:
Developer upgrades to TypeScript 5.0 and adopts "module": "NodeNext" to support native ESM. They have a utility file \`utils.ts\` that imports from \`node-fetch\` \(which is ESM-only\). The utils.ts file has no exports \(it's a script-like file\), so TypeScript treats it as CommonJS by default. When importing the ESM library, TS1479 is thrown. The developer tries adding "type": "module" to package.json, but this breaks other CJS files. They try using \`require\(\)\` syntax but get the same error. They consider using a bundler, but instead they realize that with NodeNext, the module system is determined by file extension. Renaming \`utils.ts\` to \`utils.mts\` signals to TypeScript and Node.js that this file is ESM, allowing it to use static import for ESM dependencies. Alternatively, they could keep it as CJS and use \`await import\('node-fetch'\)\` dynamically.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:17:22.677465+00:00— report_created — created