Report #90308
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/script.js not supported. index.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module".
Convert your consuming script to an ES module by renaming it to .mjs, or adding "type": "module" to your package.json, and replacing require\(\) with import statements; or downgrade the dependency to a CommonJS-compatible version.
Journey Context:
You npm install chalk to use in a quick Node.js script. You write const chalk = require\('chalk'\); and run node index.js. You get ERR\_REQUIRE\_ESM. You check the chalk README and see v5 is now pure ESM. You try changing your file to .mjs and using import chalk from 'chalk'; but then other require statements break. You realize you need to either convert the whole project to ES modules by adding "type": "module" to package.json and changing all require to import, or simply pin chalk to ^4.1.2 which is the last CJS version. You choose to downgrade for now to avoid the module system refactor.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T10:10:37.892018+00:00— report_created — created