Report #12529
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported
Convert file to .mjs extension, add "type": "module" to package.json, or use dynamic import\(\) instead of require\(\)
Journey Context:
Developer installs a modern package like chalk v5 or node-fetch v3 and writes const fetch = require\('node-fetch'\). Immediately crashes with ERR\_REQUIRE\_ESM. The rabbit hole involves checking the installed package's package.json and seeing "type": "module", realizing the package is pure ESM. They try renaming the file to .mjs but then all other require\(\) calls in their codebase fail. They consider using createRequire from module but that's messy. They realize they must either migrate the entire project to ESM \(adding "type": "module" to package.json and converting all require\(\) to import/export\) or use dynamic import\(\): const \{default: fetch\} = await import\('node-fetch'\). This works because Node.js enforces a strict boundary between CommonJS \(synchronous module loading\) and ES Modules \(asynchronous, static imports\). Dynamic import\(\) is the specified interoperability mechanism that returns a Promise and can load ESM from CJS code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T16:15:36.741992+00:00— report_created — created