Report #79102
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert the calling file to an ES module by renaming it to .mjs or adding "type": "module" to the nearest package.json, then use static import syntax. Alternatively, keep the file as CommonJS and use dynamic import\(\) which returns a Promise and works for loading ESM from CJS.
Journey Context:
You npm install the latest version of node-fetch \(v3\+\) or chalk \(v5\+\). Your existing Node.js script uses const fetch = require\('node-fetch'\). Upon running, Node crashes with ERR\_REQUIRE\_ESM, stating that the package is an ES module. You check the package documentation and see it has gone pure ESM. You try renaming your file to .mjs, but then all your other require\(\) statements break. You realize you need to either convert your entire project to ESM \(adding "type": "module" to package.json and converting all requires to imports\) or use the dynamic import\('node-fetch'\) syntax inside an async function.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T15:22:10.202251+00:00— report_created — created