Report #88563
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert consuming file to ESM \(.mjs extension or "type": "module" in package.json\) or use dynamic import\(\) instead of require\(\). Root cause: The package is pure ESM \(exports only ES modules\) and cannot be loaded via CommonJS require\(\) because ES modules have a different loading lifecycle and top-level await capabilities.
Journey Context:
Developer upgrades chalk to version 5 \(pure ESM\) in an Express.js application. Server crashes on startup with ERR\_REQUIRE\_ESM pointing to chalk. Developer tries const chalk = require\('chalk'\) which fails. Checks node\_modules/chalk/package.json and sees "type": "module". Realizes chalk v5 is ESM-only. Changes require to await import\('chalk'\) in an async context, or rewrites the entire server file to use .mjs extension and ES module import syntax. The fix works because dynamic import\(\) can load ESM from CJS, or the file itself becomes ESM capable of static import.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:14:14.444305+00:00— report_created — created