Report #56288
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported
Convert to ESM by adding \`"type": "module"\` to package.json and using \`.js\` extensions for imports, use dynamic \`import\(\)\`, or downgrade the package to a CommonJS version \(e.g., chalk v4 instead of v5\).
Journey Context:
Developer runs \`npm install chalk\` \(which is ESM-only since v5\) or \`got\` v12\+ in an existing CommonJS project. Their code uses \`const chalk = require\('chalk'\)\`. On execution, Node throws \`ERR\_REQUIRE\_ESM\`. Developer tries changing to \`import chalk from 'chalk'\` but then gets \`SyntaxError: Cannot use import statement outside a module\`. They research and learn that Node treats files as CommonJS by default. They consider renaming files to \`.mjs\`, but that breaks other requires. The "aha" moment is realizing they have three options: \(1\) Convert entire project to ESM with \`"type": "module"\` in package.json and fix all imports to include \`.js\` extensions, \(2\) Use dynamic import: \`const \{default: chalk\} = await import\('chalk'\)\` in an async context, or \(3\) simply downgrade to \`chalk@4\` which supports CommonJS. Option 3 is often chosen for immediate relief.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T00:58:25.363781+00:00— report_created — created