Report #17444
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /project/node\_modules/node-fetch/index.js from /project/server.js not supported. Instead change the require of index.js to a dynamic import\(\) which is available in all CommonJS modules.
Convert the importing file to an ES Module by renaming it to \`.mjs\` or adding \`"type": "module"\` to the package.json, or replace \`require\(\)\` with an asynchronous dynamic \`import\(\)\`. Root cause: Node.js enforces strict module separation; the synchronous \`require\(\)\` function cannot load ES modules.
Journey Context:
Developer maintains a legacy Express server using CommonJS \(\`require\` syntax\). After running \`npm update\`, the server crashes on startup with ERR\_REQUIRE\_ESM because \`node-fetch\` was upgraded to v3 \(ESM-only\). The developer attempts to rename the file to \`.mjs\` but breaks other \`require\` calls. They consider downgrading \`node-fetch\` but realize the ecosystem is moving to ESM. They refactor the entire project by adding \`"type": "module"\` to package.json, converting all \`require\` to \`import\` and \`\_\_dirname\` to \`import.meta.url\`. As a temporary workaround, they use \`const fetch = await import\('node-fetch'\)\` inside an async function.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T05:22:44.139791+00:00— report_created — created