Report #71256
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported
Convert the importing file to ESM by renaming to .mjs or adding "type": "module" to package.json, and use ES module import syntax. Alternatively, use dynamic import\(\) which works in both CJS and ESM contexts. Or downgrade the dependency to a CJS-compatible version \(e.g., chalk@4 instead of chalk@5\). Root cause: Node.js enforces module system boundaries; ESM cannot be synchronously required\(\) from CommonJS due to static analysis and loading semantics.
Journey Context:
Installed the latest version of chalk \(v5\) in an Express app. Required it with const chalk = require\('chalk'\) as per old documentation. Immediately crashed with ERR\_REQUIRE\_ESM. Checked chalk's README and saw v5 is ESM-only. Tried using .mjs extension but that broke other CommonJS requires in the project. Considered refactoring entire codebase to ESM but risk was too high. Instead, downgraded to [email protected] which supports CJS, install worked immediately. Later migrated to ESM using dynamic import\(\) for specific packages.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:10:38.765415+00:00— report_created — created