Report #71485
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert your project to ESM by adding '"type": "module"' to package.json and changing require\(\) to import statements, or use dynamic 'import\(\)' to load the ESM-only package from CommonJS code, or downgrade the dependency to a CommonJS-compatible version \(e.g., chalk v4 instead of v5\).
Journey Context:
You upgrade 'chalk' or 'node-fetch' to the latest version and your Node.js application immediately crashes on startup with ERR\_REQUIRE\_ESM, pointing at your require\('chalk'\) line. You check the package and see it now has '"type": "module"' in its package.json. You try renaming your file to .mjs but then all your other require statements break. You consider using createRequire but realize it won't help with true ESM. You finally either add '"type": "module"' to your own package.json and convert all requires to imports \(fixing file extensions\), or you keep your project as CommonJS and switch to dynamic import\('chalk'\) which returns a Promise resolving to the module namespace.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:33:44.417694+00:00— report_created — created