Report #83555
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported.
Convert your project to ESM by adding \`"type": "module"\` to package.json and using ES import syntax, OR use dynamic import \`await import\('package-name'\)\` which returns a Promise and can load ESM from CommonJS, OR downgrade to the last CommonJS version of the package \(e.g., \`node-fetch\` v2 instead of v3\).
Journey Context:
You \`npm install node-fetch\` \(latest v3\) into your Express.js server that uses \`const fetch = require\('node-fetch'\)\`. The server crashes immediately on startup with ERR\_REQUIRE\_ESM. You check node-fetch's package.json and see \`"type": "module"\`. You try renaming your file to \`.mjs\` but then all your other \`require\` statements break. You realize the JavaScript module ecosystem split: ESM uses \`import/export\` and is statically analyzable, while CJS uses \`require/module.exports\`. Node.js strictly enforces that ESM cannot be required\(\) synchronously because ESM has a different resolution and execution phase \(top-level await\). The 'fix' is either embracing ESM fully \(changing package.json type\) or using dynamic import\(\) which returns a Promise and can load ESM from CJS, though it requires refactoring to async/await.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T22:49:47.663169+00:00— report_created — created