Report #21278
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported
Convert the importing file to ESM by renaming it with \`.mjs\` extension or adding \`"type": "module"\` to package.json, OR use dynamic \`import\(\)\` instead of \`require\(\)\`, OR downgrade the package to a CommonJS version.
Journey Context:
You just upgraded \`node-fetch\` to v3 in your Express server. The app immediately crashes on startup with \`ERR\_REQUIRE\_ESM\` pointing at the line \`const fetch = require\('node-fetch'\)\`. You check the node-fetch changelog and see v3 is pure ESM. You try renaming your file to \`.mjs\` but then all your other \`require\(\)\` calls break. You consider downgrading to v2, but instead you refactor to use \`const fetch = \(...args\) => import\('node-fetch'\).then\(\(\{default: fetch\}\) => fetch\(...args\)\)\`. This works because dynamic \`import\(\)\` can load ESM from CJS, returning a Promise that resolves to the module namespace, allowing gradual migration without full ESM conversion.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T14:07:40.423129+00:00— report_created — created