ProjectStack
npm

ERR_REQUIRE_ESM — Must use import to load ES Module

You're using require() to load a package that has switched to ESM-only distribution. These packages can only be loaded with import statements, not require().

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

  1. Use a dynamic import instead: const module = await import('package-name')
  2. Pin to the last CommonJS version of the package (e.g. node-fetch@2, chalk@4)
  3. Convert your project to ESM by adding "type": "module" to package.json
  4. 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.