Report #80085
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported
Convert the importing file to ESM by renaming it to \`.mjs\`, or add \`"type": "module"\` to your package.json to enable ESM globally, then use \`import\` syntax instead of \`require\(\)\`. If you must stay in CommonJS, use dynamic \`import\(\)\` \(which returns a Promise\) to load the ESM module asynchronously.
Journey Context:
You upgrade \`node-fetch\` to v3.x in your Express.js backend. Suddenly the server crashes on startup with ERR\_REQUIRE\_ESM pointing to \`node-fetch\`. You check the node-fetch docs and realize v3 is ESM-only. You try changing \`const fetch = require\('node-fetch'\)\` to \`import fetch from 'node-fetch'\` but get a syntax error because your file is \`.js\` and your package.json lacks \`"type": "module"\`. You consider renaming to \`.mjs\`, but that breaks other \`require\(\)\` calls in the same file. Finally, you refactor to use dynamic import: \`const \{default: fetch\} = await import\('node-fetch'\)\`, which works because dynamic \`import\(\)\` is supported in CommonJS files. Alternatively, you downgrade to node-fetch v2 which remains CommonJS compatible.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:01:42.502154+00:00— report_created — created