ERR_REQUIRE_ESM in Node.js — What It Means and How to Fix It
What the Node.js/npm error ERR_REQUIRE_ESM means and how to resolve it.
Published October 25, 2026
This error occurs when CommonJS code uses require() to load a package that is ES-module only.
What it means and why it happens
Many packages (chalk 5, node-fetch 3) went ESM-only. Fix by using import, dynamic import() or pinning an older CommonJS version.
Read the full message: it names the file and line where the problem was detected, which is the best place to start.
What you see
run the code
Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/chalk/source/index.js not supported
Practical examples
Code that triggers it
const chalk = require('chalk') // v5 is ESM onlyThe fix
import chalk from 'chalk' // with "type": "module"
// or CommonJS:
const chalk = (await import('chalk')).defaultSwitch the project to ESM
{ "type": "module" }Common mistakes
- Mixing require and import.
- Missing file extensions in ESM.
- Upgrading packages without checking module type.
Key takeaways
- ERR_REQUIRE_ESM: This error occurs when CommonJS code uses require() to load a package that is ES-module only.
- Read the message and the line number first.
- Fix the cause, don't just silence the error.
FAQ
Stay on CommonJS?
Pin the last CommonJS version, e.g. chalk@4.
How do I find which line caused ERR_REQUIRE_ESM?
The error message and stack trace show the file and line; start there and work backwards.