ERR_REQUIRE_ESM: require() of ES Module not supported
Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/some-pkg/index.js not supported.
In short: CommonJS code (require) is loading a package that only ships ES modules (import).
Why it happens
Many packages are now ESM-only. Older Node versions can't require() them at all. Node 22.12+ and 20.19+ support require() of most synchronous ES modules by default, so upgrading Node often fixes it. The reverse error, require is not defined in ES module scope, means a .js file in a "type": "module" package uses require.
How to fix it
- Check your Node version:
node -v. Upgrade to a current LTS if you're older than the versions above. - Or switch the file to ESM: use
import, set"type": "module"inpackage.json(or rename to.mjs). - If you must stay CommonJS, load the package with dynamic
await import('pkg'). - Make sure your host builds and runs on the same Node version (set it in the host's settings or
engines.node).
Copy-paste fix prompt
I'm getting this error in my app: Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/some-pkg/index.js not supported. [Paste the full error, stack trace, and the file it points to here] Likely cause: CommonJS code (require) is loading a package that only ships ES modules (import). Task: Determine whether this project is CommonJS or ESM, which package is ESM-only, and our Node version. Recommend the smallest fix (Node upgrade, ESM switch, or dynamic import) and apply it consistently. Rules: - First explain the root cause in 2 sentences and list the files you'll change. - Make the smallest change that fixes it. Don't refactor unrelated code. - Don't disable security or checks (RLS, auth, signature verification, type checking, CORS allow-all) to make the error disappear. - Never print or hard-code secret keys. - Finish by telling me exactly how to verify the fix.
Common with: Cursor, Claude Code, Replit. Last reviewed 2026-11-13.