Report #27048
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert the requiring file to ESM by renaming it with .mjs extension, adding type: module to package.json, or use dynamic import\(\) instead of require\(\) to load the ESM package asynchronously.
Journey Context:
You are maintaining a legacy CommonJS Express server. You run npm update and suddenly the server crashes on startup with ERR\_REQUIRE\_ESM. The stack trace points to the line const fetch = require\('node-fetch'\). You check node\_modules/node-fetch/package.json and see type: module, indicating version 3.x is pure ESM. You check your package.json and see no type field, meaning you are in CommonJS mode. You consider downgrading to node-fetch@2, but instead decide to modernize. You rename server.js to server.mjs, update the scripts in package.json to use the new filename, and convert all require\(\) to import statements, or alternatively, you change the specific line to const fetch = \(...args\) => import\('node-fetch'\).then\(\(\{default: fetch\}\) => fetch\(...args\)\); to use dynamic import.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:48:02.083242+00:00— report_created — created