Report #85520
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported. Instead change the require ... to a dynamic import\(\)
Convert the importing file to ES Module syntax \(rename to .mjs or add 'type': 'module' to package.json and change require to import\), or use dynamic import\('module'\) which returns a Promise and works in CommonJS files.
Journey Context:
A developer maintains a Node 12 CommonJS project using require\(\). They npm install the latest version of a popular utility library \(e.g., chalk 5.x or node-fetch 3.x\). Their code has const pkg = require\('new-lib'\). Immediately on startup, Node crashes with ERR\_REQUIRE\_ESM. Confused because the file exists in node\_modules, they check the package and see 'type': 'module' in its package.json. They realize the package is ESM-only. They try renaming their file to .mjs, but that breaks their other CommonJS requires. They search and find that Node requires ESM to be imported via import statements or dynamic import\(\). They refactor their code to use await import\('new-lib'\) inside an async function. This works because dynamic import\(\) is the interoperability bridge allowing CommonJS to load ESM modules at runtime.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:07:57.016994+00:00— report_created — created