Skip to main content
DevOps Insightsguides & answers

Node.js · troubleshooting

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

CommonJS code called require() on a package or file that is an ES module, and this Node.js version cannot load ES modules that way. Newer Node.js can, except for modules that use top-level await.

Reproduced on Node.js 25.9.0, . Where the text says “reproduced”, the behaviour was run on that version, not taken from documentation.

First published

New to this? Read what is actually happening first, then come back to the steps.

On this page · 8 sections

Before you start

  • Your Node.js version (node -v), and which package or file the error names.

Run this first

step 1 of 1
node -v

Look for Older than 22.12.0 (or 20.19.0)

Most cases of this error depend on the version alone.

Work out which cause you have

A few questions to narrow the list. Every answer ends in a command that confirms or rules the cause out — this cannot see your cluster, so nothing here is a certainty until you have checked.

Narrow it down

0 answered · nothing is sent anywhere

Which error code do you see?

Cause space

3 of 3 still possible

  • This Node.js version cannot require() ES modulesCommon
  • The ES module uses top-level awaitOccasional
  • A tool loads modules with its own CommonJS loaderOccasional

Nothing ruled out yet. Answer the question above and the branches your answer eliminates will strike through here.

Or diagnose it manually

In this order. The first command usually contains the whole answer.

  1. Step 1

    node -v

    Most cases of this error depend on the version alone.

    Look for Older than 22.12.0 (or 20.19.0)

Every cause, and how to fix it

Ordered by how often each one turns out to be the answer.

This Node.js version cannot require() ES modules

Common

Before v22.12.0 (v20.19.0 on the 20 line), require() of an ES module always fails, typically after a dependency upgrade to an ESM-only major version.

Confirm

node -v

A version older than 22.12.0 or 20.19.0

Fix

  • Upgrade Node.js to a supported line where require(esm) works (22.12+, 24 or later).
  • Or load the module with import(): const { thing } = await import("pkg") inside an async function.
  • Or stay on the dependency's last CommonJS major version for now, and plan the move.

The ES module uses top-level await

Occasional

require() is synchronous, so even new Node.js cannot require() a module that has to await something while loading.

Confirm

node --experimental-print-required-tla your-entry.cjs

The location of the top-level await, which Node prints with this flag

Fix

  • Use import() for that module, or move your own code to ES modules and use import.

A tool loads modules with its own CommonJS loader

Occasional

Test runners and TypeScript runners that transform code to CommonJS can produce this error even on new Node.js. Not reproduced here.

Confirm

node -e "require('PACKAGE')"

It works in plain node but fails under the tool

Fix

  • Configure the tool for ES modules or to transform that dependency, following its documentation.

Understanding it properly

Skip this if you are mid-incident — the working part of the page is above. Worth reading afterwards, because understanding the mechanism is what stops the next one.

In plain terms

Many packages now ship only as ES modules. Older Node.js cannot require() those at all, which is this error; newer Node.js can, unless the module waits for something at load time (top-level await). The fixes are to load it with import() instead, upgrade Node.js, or move your own code to ES modules.

Words used on this page

require()
CommonJS's way of loading a module, synchronously.
import()
Loading a module asynchronously; works in both CommonJS and ES modules and returns a promise.
Top-level await
await used at the top of an ES module, outside any function, which makes loading it asynchronous.
What is actually happening

Reproduced on 22 October 2026. On Node.js 18.19.1, require("./lib.mjs") threw "Error [ERR_REQUIRE_ESM]: require() of ES Module …/lib.mjs not supported", with the advice to use a dynamic import() instead.

On Node.js 25.9.0 the same require() simply worked. Node's documentation says require() of ES modules is enabled by default from v22.12.0 and v20.19.0, and no longer experimental from v24.15.0 and v25.4.0. So upgrading Node.js removes most cases of this error.

One case remains on new versions: an ES module that uses top-level await. Node.js 25.9.0 threw "Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead." import() worked on both versions in every case.

How to tell this is your problem
WhereWhat you see
Node.js before 22.12 / 20.19Error [ERR_REQUIRE_ESM]: require() of ES Module … not supported
Node.js 22.12+ / 20.19+Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await

How to know it is actually fixed

  • The module loads, through require() on new Node.js or through import().

Stopping it happening again

  • Run a Node.js version where require(esm) is on by default, and check engines in package.json says so.
  • Read a dependency's changelog before a major upgrade: moving to ESM-only is usually announced there.

Sources

Behaviour described here is drawn from official documentation. Where a figure could not be confirmed on an official page it is attributed in the text rather than stated as canonical.

Did this get you to an answer?

No text box on purpose — please do not paste production logs anywhere

Something wrong or out of date? Report it