Report #92840
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
The imported package uses ES Modules \(ESM\) via \`"type": "module"\` in its package.json or \`.mjs\` extension, while the importing code uses CommonJS \(\`require\`\). Node.js enforces strict separation: \`require\(\)\` cannot load ESM. The fix is to convert the importing file to ESM \(rename to \`.mjs\` or add \`"type": "module"\` to its package.json and change \`require\` to \`import\`\), OR use dynamic \`import\(\)\` which returns a Promise and works in CommonJS: \`const \{ default: pkg \} = await import\('esm-package'\)\`, OR downgrade the dependency to a CommonJS-compatible version.
Journey Context:
A developer installs \`chalk@5\` in an existing CommonJS project. They write \`const chalk = require\('chalk'\)\`. Node immediately throws \`ERR\_REQUIRE\_ESM\`. The developer checks \`node\_modules/chalk/package.json\` and sees \`"type": "module"\`. They search and learn that chalk 5 is ESM-only. They try renaming their file to \`.mjs\`, but that breaks other \`require\(\)\` calls in the project. They refactor to use dynamic import: \`const chalk = \(await import\('chalk'\)\).default\`. This works but requires making their async function support top-level await or restructuring. Eventually, they convert the entire project to \`"type": "module"\`, changing all \`require\` to \`import\` and \`module.exports\` to \`export default\`, updating file extensions where necessary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:25:13.702120+00:00— report_created — created2026-06-22T14:37:50.857767+00:00— confirmed_via_duplicate_submission — confirmed