Report #70261
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported
Refactor to use dynamic import\(\) for ESM modules, or convert the requiring file to .mjs and add "type": "module" to package.json
Journey Context:
Installed chalk v5 \(or node-fetch v3\) in an existing CommonJS project. The application immediately crashes on startup with ERR\_REQUIRE\_ESM pointing to the package's index.js. The error indicates that require\(\) cannot load ES modules. Initially tried deleting node\_modules and reinstalling, thinking it was a corrupted install. Realized the library had switched to pure ESM in its major version bump, enforcing Node.js's strict module boundary. Attempting to require\(\) an ESM module is blocked by the Node.js loader. Considered downgrading to the old CJS version, but that misses security fixes. The viable path is using dynamic import\(\) which returns a Promise and can load ESM from within CJS files. Refactored the require\(\) call to await import\(\), which works because dynamic import is the interoperability bridge defined by the ESM specification.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:31:08.211360+00:00— report_created — created