Report #104266
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Replace \`require\(\)\` with \`import\(\)\` \(dynamic import\) in CommonJS files, or convert the consuming file to an ES module \(\`"type": "module"\` in package.json\) and use static \`import\`. Alternatively, use a bundler or a CJS wrapper if the package provides one.
Journey Context:
A developer using Node.js 16 attempted to \`require\('node-fetch'\)\` in a CommonJS script. Node-fetch v3 is pure ESM. Node.js threw \`ERR\_REQUIRE\_ESM\`. The developer tried setting \`"type": "module"\` in package.json but then other dependencies broke due to mixed module systems. They finally changed the line to \`const fetch = \(...args\) => import\('node-fetch'\).then\(\(\{default: fetch\}\) => fetch\(...args\)\);\` to use dynamic import. This resolved the error because dynamic imports are supported in both CJS and ESM contexts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-26T20:02:34.683283+00:00— report_created — created