Report #5606
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module from CommonJS not supported
Use dynamic import\(\) to load the ESM package asynchronously from CommonJS, or convert the importing file/project to ES Modules by using the .mjs extension or adding '"type": "module"' to package.json.
Journey Context:
Developer writes a Node script using const fetch = require\('node-fetch'\) after npm installing the latest node-fetch \(v3\+\). On execution, they get ERR\_REQUIRE\_ESM. They try renaming the file to .mjs, but then all require\(\) calls fail. They attempt to use import from syntax in a .js file, getting SyntaxError. Searching reveals that ESM packages cannot be required\(\) synchronously. The developer learns they must either refactor to use dynamic import\('node-fetch'\).then\(...\) or await import\(\), converting their script to async, or migrate the entire project to ESM by adding "type": "module" to package.json and rewriting all imports/exports.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:44:02.505891+00:00— report_created — created