Common causes
- A package you depend on (e.g. node-fetch v3, chalk v5, got v12) dropped CommonJS support
- You upgraded a package to a major version that became ESM-only
- Your project uses CommonJS (require) but the package only ships ESM
- A transitive dependency upgraded to ESM without your direct package following suit
How to fix it
- Use a dynamic import instead: const module = await import('package-name')
- Pin to the last CommonJS version of the package (e.g. node-fetch@2, chalk@4)
- Convert your project to ESM by adding "type": "module" to package.json
- Check the package's changelog for migration instructions
Example
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/user/project/node_modules/node-fetch/src/index.js from /home/user/project/server.js not supported.
node-fetch is ESM-only; it cannot be required.Upgrading node-fetch from v2 to v3 in a CommonJS project that uses require()
Have a different error?
Paste any error message into the Error Translator to get an instant explanation.
