Report #14542
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js not supported
Convert the requiring file to ESM by renaming to .mjs or adding 'type': 'module' to package.json and using import syntax, or use dynamic import\('chalk'\) instead of require\(\), or downgrade to the last CommonJS version of the package \(e.g., chalk 4.1.2\).
Journey Context:
Developer starts a new Node.js project or updates dependencies in an existing CommonJS project. Runs npm install chalk \(which installs chalk 5\+\). In their index.js, they have const chalk = require\('chalk'\). When they run node index.js, they get ERR\_REQUIRE\_ESM. Confused because require\(\) worked in old projects. Checks chalk package.json and sees 'type': 'module'. Realizes chalk 5\+ is pure ESM. Considers converting entire project to ESM but worried about breaking other requires. Tries using import chalk from 'chalk' in the .js file but gets SyntaxError because file is treated as CommonJS. Eventually finds solution: either rename file to .mjs, add 'type': 'module' to package.json \(converting whole project to ESM\), use const chalk = await import\('chalk'\) which works in CommonJS because dynamic import returns a Promise, or simply downgrade to chalk 4 which is still CommonJS.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:48:41.917356+00:00— report_created — created