ERR_REQUIRE_ESM Node.js Origin: Application & API OSI layer 7 · Application Last updated 12 Oct 2026

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported

CommonJS code used require() on a package that is ES-module-only (node-fetch 3, chalk 5, nanoid 4, got 12…).

Exact message you may see require() of ES Modulenot supported. Instead change the require
Seen on: Node.js npm

Meaning

Many packages dropped CommonJS in recent major versions. Older Node versions can’t require() ESM; newer Node (22+) supports require(esm) only for synchronous modules.

Common causes

  • Upgraded a dependency to an ESM-only major version
  • Project is CommonJS (no "type": "module")
  • TypeScript compiling imports to require()

⚡ Quick fix

  1. Switch the project to ESM ("type": "module") and use import
  2. Or use dynamic import: const { default: fetch } = await import('node-fetch')
  3. Or pin the last CommonJS version of the package
  4. Node 18+: use the built-in fetch instead of node-fetch

Detailed fix by platform

Node.js

  1. Dynamic import from CommonJS:
    javascript
    // CommonJS file
    async function main() {
      const { default: chalk } = await import('chalk');
      console.log(chalk.green('ok'));
    }
    main();

How to diagnose

  1. Package — Which package and version?
  2. Module type — package.json "type"? TS module setting?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

ERR unknown command — Redis: (error) ERR unknown command 'JSON.GET', with args beginning with: / unknown command 'FT.SEARCH' (Redis)ERR unknown commandERR_IMPORT_ATTRIBUTE_MISSING — TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module needs an import attribute of "type: json" (Node.js)ERR_IMPORT_ATTRIBUTE_…ERR_PACKAGE_PATH_NOT_EXPORTED — Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './x' is not defined by "exports" (Node.js)ERR_PACKAGE_PATH_NOT_…ERR_UNKNOWN_FILE_EXTENSION — TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" (Node.js)ERR_UNKNOWN_FILE_EXTE…Jest ESM — Jest: SyntaxError: Cannot use import statement outside a module (Jest encountered an unexpected token) (React)Jest ESMMODULE_NOT_FOUND — Error: Cannot find module 'x' (MODULE_NOT_FOUND) (Node.js)MODULE_NOT_FOUNDnext.config.js: ES Module / require error — Next.js: Error [ERR_REQUIRE_ESM]: require() of ES Module next.config.js / SyntaxError: Unexpected token 'export' (Next.js)next.config.js: ES Mo…SyntaxError import — SyntaxError: Cannot use import statement outside a module (Node.js)SyntaxError importERR_REQUI…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.