Report #26439
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert the requiring file to ESM \(rename to .mjs or add "type": "module" to package.json\) and use import syntax, or use dynamic import\(\) which returns a Promise, or downgrade to a CommonJS version of the dependency.
Journey Context:
Developer npm installs a popular package \(e.g., chalk 5\+, node-fetch 3\+, or got 12\+\) and attempts to require it in their index.js using const pkg = require\('package'\). Node.js immediately throws ERR\_REQUIRE\_ESM. Developer checks the package's package.json and sees "type": "module", confirming it's a pure ESM package. They try renaming their file to .mjs but that breaks other CommonJS requires in their codebase. They consider using .cjs extension for other files but the ecosystem friction is high. Finally, they refactor the specific import to use dynamic import\('package'\) which asynchronously loads the ESM module, or they pin the dependency to an older CommonJS-compatible version \(e.g., chalk@4\) to maintain synchronous require\(\) compatibility while they migrate their codebase.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:46:55.775629+00:00— report_created — created