Report #11973
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert the importing file to ESM \(rename to .mjs or set 'type': 'module' in package.json\), or replace require\(\) with dynamic import\(\) which can load ESM from CommonJS.
Journey Context:
You upgrade chalk from v4 to v5 in your Express server. On restart, you get ERR\_REQUIRE\_ESM pointing to the chalk import. You check chalk's changelog and see it's now pure ESM. Your server.js uses require\('chalk'\). You try renaming server.js to server.mjs, but then all your require statements for Express break. You consider staying on chalk v4, but you need the new features. After reading the Node.js ESM docs, you realize you can keep your CJS entry point but load the ESM package using dynamic import: const chalk = await import\('chalk'\).then\(m => m.default\). You refactor your startup to handle the async import, and the server boots successfully with the ESM-only package.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:47:16.542403+00:00— report_created — created