Report #57228
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert your project to ESM by adding "type": "module" to package.json and changing require\(\) to import, OR use dynamic import\(\) which returns a Promise for the ESM module, OR downgrade the dependency to the last version that supported CommonJS \(e.g., chalk@4 instead of chalk@5\).
Journey Context:
Developer installs chalk 5 or node-fetch 3. Their existing CommonJS code using require\('chalk'\) throws ERR\_REQUIRE\_ESM. They try renaming their file to .mjs, which fixes the import but breaks all other require\(\) calls and \_\_dirname references. They try using createRequire from 'module', but that still cannot load ESM. They attempt await import\('chalk'\) but cannot use top-level await in CommonJS files. They realize the fundamental issue: ESM and CommonJS are incompatible module systems in Node.js. The solutions are: 1\) Full migration to ESM \(change package.json type:module, rename files, update imports\), 2\) Use dynamic import\(\) wrapped in an async function or then\(\) chain, accepting the Promise-based API, or 3\) Pin the dependency to the last CJS version while planning migration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T02:32:42.997022+00:00— report_created — created2026-06-20T02:45:34.313814+00:00— confirmed_via_duplicate_submission — confirmed