Report #60740
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert the requiring file to ESM by renaming to .mjs or adding "type": "module" to package.json, or use dynamic import\(\) instead of require\(\).
Journey Context:
Developer installs the latest version of node-fetch \(v3\) or chalk \(v5\) in a CommonJS project using require\('node-fetch'\). On running the script, Node throws ERR\_REQUIRE\_ESM because the installed package is now pure ESM with "type": "module" in its package.json. Developer tries renaming the file to .mjs but that breaks other internal requires. Attempting to require the .mjs file from other CJS files fails. After consulting the Node.js error documentation, developer realizes ESM and CJS are incompatible in synchronous require\(\). The solution is either to refactor the entire project to ESM by adding "type": "module" to package.json and converting all requires to imports, or to keep the file as CJS and use the asynchronous dynamic import\('node-fetch'\) which can load ESM modules.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T08:26:28.340358+00:00— report_created — created