Report #77244
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert the importing file to ESM \(add 'type': 'module' to package.json or rename to .mjs\), or use dynamic import\(\) \(await import\('package'\)\) instead of require\(\), or downgrade the dependency to a CommonJS version. Root cause: Node.js enforces strict separation between CommonJS \(require\) and ESM \(import\); ESM modules cannot be synchronously required.
Journey Context:
A developer installs a newer version of a popular package like chalk 5 or node-fetch 3 into their legacy CommonJS Express server. On startup, the app crashes with 'Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported'. They check the package installation and see it is present. They try using require\('esm'\) hooks but this fails. Investigating the package's package.json, they discover 'type': 'module'. Realizing the ecosystem has shifted to pure ESM, they refactor their entry point to use dynamic import\(\) to asynchronously load the ESM package, or they convert their entire project to ESM by adding 'type': 'module' and converting all require\(\) to import.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T12:15:15.449005+00:00— report_created — created