Report #35832
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported.
Add "type": "module" to package.json and convert to ES module syntax, or use dynamic import\(\) instead of require\(\), or downgrade to the CommonJS version of the dependency.
Journey Context:
Developer installs a modern package like chalk v5 or node-fetch v3 into an existing Node.js project that uses CommonJS \(require/module.exports\). Upon running the application, Node throws ERR\_REQUIRE\_ESM. The developer checks the installed package's package.json and sees "type": "module", indicating it is ESM-only. Attempting to rename the file to .mjs breaks other dependencies. The developer realizes that Node.js enforces strict separation: ESM cannot be required\(\) from CommonJS. The solution path diverges: either convert the entire project to ESM by adding "type": "module" to package.json and rewriting requires to imports, or keep the project as CommonJS and use the dynamic import\(\) function \(which returns a Promise\) to load the ESM module asynchronously, or simply downgrade to the last CommonJS version of the package \(e.g., chalk v4\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:37:12.876489+00:00— report_created — created