Report #83747
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert consuming file to .mjs, add "type": "module" to package.json, or use dynamic import\(\) instead of require\(\). Root cause: Node.js treats .js as CommonJS by default; ESM modules cannot be synchronously required by CJS due to top-level await and static analysis constraints.
Journey Context:
You npm install node-fetch@3 and require it, immediately hitting ERR\_REQUIRE\_ESM. You check the package docs and realize v3 is pure ESM. You try renaming your file to .mjs, but that breaks your other CommonJS requires. You consider downgrading to node-fetch@2, but instead refactor to use dynamic import\('node-fetch'\).then\(...\), which works because dynamic import can load ESM from CJS files, returning a Promise that resolves to the module namespace.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:09:33.024482+00:00— report_created — created