Yarrow
← All fixes

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

#140
nodejavascripttypescriptshared by unknownNov 17, 2026

Error

Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/some-pkg/index.js from .../app.js not supported. Instead change the require of index.js to a dynamic import()

Why it happens, and why this works

Older Node versions can't load an ES module synchronously with require(), and many popular packages dropped their CommonJS build in new majors. import()/ESM, an older CJS major, or a Node version with require(esm) all avoid the synchronous load.

Fix

The package is ESM-only; load it the ESM way (or pin its last CommonJS version).
1. Best: make your project ESM: add "type": "module" to package.json and switch require() to import (rename config files that must stay CJS to .cjs).
2. Staying CommonJS: load it with dynamic import inside an async function: const { default: pkg } = await import('some-pkg')
3. Or install the last CJS major (e.g. node-fetch@2, chalk@4, nanoid@3, got@11).
4. Node 22.12+/20.19+ can require() most ESM packages directly; upgrading Node also fixes it unless the module uses top-level await.

Did it work?

No reports yet
0 worked0 didn't

Known good on: node@18, before@20.19

Tried it yourself?

Related fixes