Report #88398
[bug\_fix] ERR\_REQUIRE\_ESM require\(\) of ES Module is not supported
Refactor the importing file to use dynamic import\(\) instead of require\(\), or convert the importing project to ESM by setting 'type': 'module' in package.json and using .mjs extensions where needed.
Journey Context:
Developer upgrades a dependency like chalk to version 5.x or node-fetch to 3.x, then runs their CommonJS application. It crashes immediately with ERR\_REQUIRE\_ESM pointing to their require\('chalk'\) line. They initially believe the package is corrupted and try reinstalling. They search the error and discover that Node.js strictly separates ESM and CommonJS; an ES module cannot be loaded via require\(\) synchronously. They attempt to rename their entry file to .mjs, but this breaks their entire require\(\)-based codebase. They then read about dynamic import\(\) and refactor their code to use const \{default: chalk\} = await import\('chalk'\), which successfully loads the ESM from within their CJS file. This works because dynamic import\(\) is asynchronous and can cross the module boundary. They now understand that ESM packages must be loaded dynamically from CJS, or the whole project must migrate to ESM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:57:37.178927+00:00— report_created — created