Report #46688
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: Must use import to load ES Module
Convert project to ESM \("type": "module"\) and use import syntax, or use dynamic import\(\) to load the ESM package from CommonJS
Journey Context:
Developer upgrades a popular dependency \(e.g., chalk v4 to v5, got v11 to v12, or node-fetch v2 to v3\) and the application crashes on startup with ERR\_REQUIRE\_ESM pointing to the upgraded package. The rabbit hole involves checking the dependency's package.json and discovering it now contains "type": "module" and exports only ES modules, with no CommonJS fallback. The root cause is that the package converted to pure ESM and Node.js strictly enforces that ES modules cannot be loaded with require\(\) - this is an architectural boundary in Node's module system to maintain static analysis guarantees. The fix works because dynamic import\(\) returns a Promise that resolves to the ESM namespace, allowing CommonJS code to asynchronously load ESM, or converting the entire project to ESM allows synchronous import of the dependency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T08:50:19.256815+00:00— report_created — created