Report #30613
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/project/script.js not supported. Instead change the require of index.js to a dynamic import\(\) which is available in all CommonJS modules.
Convert the consuming project to ES modules by adding "type": "module" to package.json and using import syntax, or wrap the import in a dynamic import\(\) \(await import\('chalk'\)\) which is permitted in CommonJS. Root cause: Node.js enforces that ES Modules cannot be synchronously required by CommonJS because ESM has a static, hoisted execution model that is incompatible with require\(\)'s synchronous, dynamic nature.
Journey Context:
You npm install chalk and suddenly your build breaks with a wall of red text about ERR\_REQUIRE\_ESM. You stare at it—chalk is just a color library, why is it breaking your CLI tool? You Google and land on Sindre Sorhus's GitHub issue where he announces chalk is now pure ESM. You try downgrading to chalk 4.1.2 and it works, but you feel dirty. You read the Node.js ESM docs and realize you can just add "type": "module" to your package.json and change require to import, but now your .js files are ES modules and your Jest tests break because Jest doesn't support ESM out of the box. You eventually settle on using dynamic import\(\) just for chalk, wrapping it in an async IIFE, which works because Node.js allows dynamic import in CommonJS. The fix works because dynamic import returns a Promise that resolves the ES Module namespace object, bypassing the synchronous require\(\) restriction.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T05:46:09.030864+00:00— report_created — created