Report #5
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: Must use import to load ES Module
Rename the consuming file to \`.mjs\`, or add \`"type": "module"\` to package.json, or switch the import to a dynamic \`import\('chalk'\)\` inside a CommonJS file. The root cause is that Node.js treats \`.js\` files as CommonJS by default; a package published as pure ESM \(e.g. chalk v5\) cannot be loaded with \`require\(\)\`.
Journey Context:
You upgrade \`chalk\` from v4 to v5 in a CLI tool and every \`require\('chalk'\)\` immediately throws ERR\_REQUIRE\_ESM. At first you think the package is broken because the import path looks right. You check node\_modules/chalk/package.json and see \`"type": "module"\`, confirming it is ESM-only. You try \`const chalk = await import\('chalk'\)\` and the error goes away, but now you are deep in async/await refactoring. The cleanest fix is flipping the whole project: add \`"type": "module"\` to package.json and convert top-level \`require\`/\`module.exports\` to \`import\`/\`export\`. After renaming test files and adding \`.cjs\` config where needed, the CLI builds and runs. You realize ESM is not a drop-in replacement; it is a module-system boundary enforced by Node.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-11T22:20:08.451585+00:00— report_created — created