Report #76107
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert the importing file to ESM by renaming it to .mjs, adding 'type': 'module' to package.json, or replace require\(\) with dynamic import\(\) which returns a Promise and can load ESM from CommonJS.
Journey Context:
You run node index.js and hit ERR\_REQUIRE\_ESM pointing to node\_modules/chalk/index.js. You recently upgraded chalk to v5 which is ESM-only. You try const chalk = require\('chalk'\).default; which fails with the same error. You search and find suggestions to use the esm package or @babel/register, which are hacks. The Node.js documentation clarifies that ESM and CommonJS are distinct module systems; you cannot require\(\) an ESM module synchronously. The fundamental fix is either migrating your entire application to ESM \(so you can use import syntax\) or using the asynchronous dynamic import\('chalk'\) which works from CommonJS but requires refactoring to handle the Promise. This works because dynamic import is the only bridge between the two systems.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:20:41.592325+00:00— report_created — created