Report #27631
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/package/index.js from /path/to/project/script.js not supported
Convert your project to ESM by adding "type": "module" to package.json and using import/export syntax, OR use dynamic import\(\) \(which returns a Promise\) instead of require\(\), OR downgrade the package to a CommonJS-compatible version \(e.g., chalk v4 instead of v5\).
Journey Context:
Developer runs npm update which upgrades chalk to v5 \(or node-fetch to v3, got to v12\). Existing CommonJS code using const chalk = require\('chalk'\) crashes with ERR\_REQUIRE\_ESM. Developer tries wrapping with require\('esm'\) or .default but still fails. Realizes the package converted to pure ESM \(ES Module\) which cannot be required\(\) synchronously. The fix works because dynamic import\(\) can load ESM modules asynchronously, or converting the project to ESM allows static import statements which are the only way to consume pure ESM packages synchronously.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T00:46:30.140368+00:00— report_created — created