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
- Replace the require() with an await import() inside an async function.
- Read the default export off the resolved module namespace.
JavaScript
const { default: chalk } = await import('chalk');Pin a CommonJS-compatible version
- If converting to ESM is not feasible, pin the last release that shipped CommonJS.
- Schedule the ESM migration separately.
Terminal
npm install chalk@4How 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
Node "Cannot use import statement outside a module" in CI - Fix ItFix the Node.js "SyntaxError: Cannot use import statement outside a module" in CI by telling Node to treat th…
Node CJS/ESM Default Import "is not a function" in CI - Fix the InteropFix a CommonJS-from-ESM default-import "is not a function" error in CI by reading the real callable off the i…
Node ERR_MODULE_NOT_FOUND on ESM Import in CI - Fix Specifier ResolutionFix the Node.js ERR_MODULE_NOT_FOUND error in CI by adding the missing file extension or correcting the ESM i…