Report #15742
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js not supported
Convert your project to ESM by adding \`"type": "module"\` to \`package.json\` and converting all \`require\(\)\` to \`import\`, or use a dynamic import \`await import\('chalk'\)\` \(which works in CommonJS files to load ESM asynchronously\), or downgrade the dependency to a CommonJS-compatible version \(e.g., chalk v4 instead of v5\).
Journey Context:
A developer is maintaining a legacy Node.js CLI tool written in CommonJS \(\`require\`\). They decide to update the \`chalk\` package to get the latest features, running \`npm install chalk@latest\` \(v5\). Immediately upon running the CLI, it crashes with \`ERR\_REQUIRE\_ESM\`. The developer is confused because the \`require\('chalk'\)\` syntax hasn't changed. They read the error message and the chalk README, realizing v5 is ESM-only. They attempt to use \`require\('chalk'\).default\`, which fails. They consider downgrading to v4, but instead decide to modernize. They add \`"type": "module"\` to \`package.json\`, rename the entry file to \`.mjs\` temporarily to test, and convert all \`require\` statements to \`import\` and \`module.exports\` to \`export\`. The CLI now works with chalk v5.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:52:54.097697+00:00— report_created — created