Report #50077
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/module.mjs not supported
Convert the requiring file to ESM by renaming it to .mjs, adding \`"type": "module"\` to package.json, or use dynamic \`import\(\)\` which returns a Promise and works from CommonJS to load ESM.
Journey Context:
You install the latest version of \`node-fetch\` \(v3\+\) or \`chalk\` \(v5\+\) and your \`require\('node-fetch'\)\` crashes with "ERR\_REQUIRE\_ESM". You check the package and it's "type": "module". You realize the ecosystem is moving to ESM-only. You try \`require\(\).default\` but that fails. You rename your file to \`index.mjs\` and change \`require\` to \`import\`, or you keep it as CommonJS and switch to \`const fetch = await import\('node-fetch'\).then\(m => m.default\)\`. The dynamic import works because it's asynchronous and ESM-compatible.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T14:32:25.419186+00:00— report_created — created