Skip to content
Latchkey

Node ERR_REQUIRE_ESM "require() of ES Module" in CI - Fix the Interop

ERR_REQUIRE_ESM means CommonJS code called require() on a package that only ships an ES module. On older Node, require cannot load ESM synchronously.

What this error means

A node script throws Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported, usually after upgrading a dependency that went ESM-only.

node
Error [ERR_REQUIRE_ESM]: require() of ES Module
/home/runner/work/app/app/node_modules/chalk/source/index.js
from /home/runner/work/app/app/src/log.js not supported.
Instead change the require of index.js to a dynamic import().

Common causes

A dependency dropped CommonJS support

The package now publishes ESM only, so a require() of it can no longer load synchronously on Node versions before the require(esm) support.

A CommonJS caller importing an ESM-only module

Your entry point is CommonJS but it pulls in a module that exposes no CommonJS entry.

How to fix it

Use a dynamic import

  1. Replace the require() with an await import() inside an async function.
  2. Read the default export off the resolved module namespace.
JavaScript
const { default: chalk } = await import('chalk');

Pin a CommonJS-compatible version

  1. If converting to ESM is not feasible, pin the last release that shipped CommonJS.
  2. Schedule the ESM migration separately.
Terminal
npm install chalk@4

How to prevent it

  • Track which dependencies have gone ESM-only, plan a deliberate move of the consuming package to ESM, and avoid mixing synchronous require with ESM-only modules.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →