Report #59825
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... from ... not supported
Convert to ESM by adding "type": "module" to package.json and using import syntax, OR use dynamic import\(\): const chalk = await import\('chalk'\), OR downgrade to last CJS version
Journey Context:
Developer upgrades chalk from v4 to v5 in a CommonJS project. On the next run, Node.js crashes with ERR\_REQUIRE\_ESM. The stack trace points to the line const chalk = require\('chalk'\). Developer checks the chalk changelog and sees v5 is now pure ESM. The confusion arises because ES Modules \(ESM\) and CommonJS \(CJS\) are distinct module systems with different loading phases. Node.js cannot synchronously require\(\) an ESM because ESM has a separate graph resolution and loading phase that doesn't allow the synchronous evaluation that require expects. The developer has three valid paths: convert the entire project to ESM by adding "type": "module" to package.json \(allowing import syntax\), keep the project CJS but use dynamic import\(\) which returns a Promise and can load ESM asynchronously, or simply downgrade to chalk v4 which remains CommonJS. The dynamic import fix works because it defers loading to the ES Module Loader which can handle the different module format.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T06:54:21.841086+00:00— report_created — created