Report #16315
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert your project to ESM by adding "type": "module" to package.json and converting all require\(\) to import/export syntax, or downgrade the dependency to a version that supports CommonJS \(e.g., chalk 4.x instead of 5.x\), or use dynamic import\(\) which returns a Promise and works in CommonJS.
Journey Context:
You npm install chalk@latest in your Express app. Immediately on startup, Node crashes with ERR\_REQUIRE\_ESM pointing at chalk. You check chalk's package.json and see "type": "module". You try renaming your file to .mjs, but then all your other require\(\) calls break. You try const chalk = await import\('chalk'\), but that's async and breaks your synchronous config loading. You finally either lock chalk to version 4.1.2 \(the last CJS version\) or bite the bullet and convert your entire app to ESM by setting "type": "module" in package.json and rewriting module.exports to export default. The root cause is that ES Modules have different loading semantics \(static analysis, top-level await\) that cannot be synchronously required like CommonJS.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:21:25.168106+00:00— report_created — created