Report #84620
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert the consuming file to an ES Module \(rename to \`.mjs\` or add \`"type": "module"\` to \`package.json\` and use \`import\` syntax\), or use a dynamic \`import\(\)\` instead of \`require\(\)\`, or downgrade the dependency to a CommonJS-compatible version \(e.g., \`node-fetch@2\` instead of v3\).
Journey Context:
Developer on Node 14 LTS installs \`node-fetch\` v3 \(or \`chalk\` v5, \`got\` v12\) via \`npm install\`. In their \`index.js\` \(CommonJS\), they write \`const fetch = require\('node-fetch'\)\`. Upon running \`node index.js\`, Node throws \`ERR\_REQUIRE\_ESM\`, stating that the module is an ES Module and cannot be required. Developer checks the \`node-fetch\` \`package.json\` and sees \`"type": "module"\`. Attempting to rename \`index.js\` to \`index.mjs\` fixes the import but breaks other \`require\(\)\` calls in the project. Developer tries \`import\('node-fetch'\)\` but struggles with top-level await or refactoring to async. Eventually, the developer understands that the ecosystem is transitioning to ESM and either converts the entire project to ESM via \`package.json\` \`"type": "module"\`, or pins the dependency to the last CJS version \(\`[email protected]\`\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T00:37:41.021583+00:00— report_created — created