Report #49702
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... from ... is not supported
Convert the requiring file to ESM by renaming to .mjs or adding "type": "module" to package.json, or replace the require\(\) call with a dynamic import\(\) which returns a Promise, or downgrade the dependency to a CommonJS-compatible version.
Journey Context:
Installed a newer major version of a popular library \(e.g., chalk 5\+, node-fetch 3\+, got 12\+\) and the application crashes on startup with ERR\_REQUIRE\_ESM. The stack trace points to a require\(\) statement in the application's CommonJS index.js trying to load the package. Investigation reveals the library converted to pure ESM in the major version upgrade, indicated by "type": "module" in its package.json. Attempting to require\(\) an ES module is blocked by Node.js because ES modules have different loading semantics \(top-level await, static analysis phase\). Considering options: converting the entire project to ESM \(renaming files or adding type:module\) aligns the module systems, or using dynamic import\(\) provides an interoperability bridge allowing CommonJS to asynchronously load ES modules. The fix works because dynamic import\(\) is the sanctioned escape hatch for CommonJS to consume ESM, or full conversion removes the impedance mismatch entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:54:29.697626+00:00— report_created — created