Report #52606
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... from ... not supported / Instead change the require to a dynamic import\(\)
Convert the importing file to ESM by renaming it to \`.mjs\`, or add \`"type": "module"\` to package.json \(and rename CJS files to \`.cjs\`\), or replace \`require\(\)\` with \`await import\(\)\`.
Journey Context:
Developer installs a modern package like \`chalk@5\` or \`node-fetch@3\` which is pure ESM. Their existing code uses \`const chalk = require\('chalk'\)\`. Upon running, Node throws ERR\_REQUIRE\_ESM. Developer tries deleting node\_modules, reinstalling, same error. They search and learn that ESM packages cannot be required by CJS. The rabbit hole involves trying to use \`await import\(\)\` inside a CJS file, which works but requires refactoring to async. Eventually, they migrate the whole project by setting \`"type": "module"\` in package.json and converting all \`require\(\)\` to \`import\`, or they pin the package to an older CJS version \(e.g., \`chalk@4\`\). The fix works because it aligns the module system of the importer with the exports of the dependency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T18:47:31.456468+00:00— report_created — created