Report #104694
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/project/index.js not supported. Instead change the require of index.js in /path/to/project/index.js to a dynamic import\(\) which is available in all CommonJS modules.
Replace \`require\('chalk'\)\` with \`import\('chalk'\)\` \(dynamic import\) or convert your project to ES modules by adding \`"type": "module"\` to package.json and using \`import\` statements. Alternatively, use a CommonJS-compatible version of the package \(e.g., chalk@4\).
Journey Context:
A developer migrated a Node.js project from CommonJS to ES modules gradually. They had a file using \`require\('chalk'\)\` for coloring console output. After updating chalk from v4 to v5 \(which is ESM-only\), the script threw ERR\_REQUIRE\_ESM. The developer spent time searching for a flag or workaround, then learned that chalk v5 dropped CommonJS support. They changed the require to a top-level \`await import\('chalk'\)\` and added \`"type": "module"\` to their package.json. The fix worked because Node.js allows dynamic import inside CommonJS, but they eventually converted the entire project to ESM. The environment was Node 18.12.0, npm 8.19.2, Ubuntu 22.04.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-09-27T20:10:57.917184+00:00— report_created — created