Report #53362
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]
Convert the importing file to ESM \(.mjs extension or "type": "module" in package.json\) and use dynamic import\(\), or use Node.js flag --experimental-require-module \(Node 20\+ experimental\) to allow require\(\) of ESM.
Journey Context:
You're migrating a Node 14 Express app to Node 20. You run the app and get Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported. You stare at the error. The package some-new-lib is pure ESM now. You try changing your require\(\) to import\(\) but that breaks because it's now async and your whole codebase uses require\(\) synchronously at the top level. You consider downgrading some-new-lib to v2 \(CJS\), but that's a security risk. You read about "type": "module" but converting your whole app breaks other CJS dependencies. The journey involves trying .mjs extensions, using dynamic imports in specific places wrapped in async IIFEs, or using the --experimental-require-module flag in Node 20\+ which allows require\(\) of ESM behind a flag, or finally deciding to convert the entry point to ESM and use await import\(\) for CJS modules.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:03:46.870319+00:00— report_created — created