Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
CommonJS code used require() on a package that is ES-module-only (node-fetch 3, chalk 5, nanoid 4, got 12…).
require() of ES Modulenot supported. Instead change the require Meaning
Many packages dropped CommonJS in recent major versions. Older Node versions can’t require() ESM; newer Node (22+) supports require(esm) only for synchronous modules.
Common causes
- Upgraded a dependency to an ESM-only major version
- Project is CommonJS (no "type": "module")
- TypeScript compiling imports to require()
⚡ Quick fix
- Switch the project to ESM (
"type": "module") and useimport - Or use dynamic import:
const { default: fetch } = await import('node-fetch') - Or pin the last CommonJS version of the package
- Node 18+: use the built-in
fetchinstead of node-fetch
Detailed fix by platform
Node.js
- Dynamic import from CommonJS:javascript
// CommonJS file async function main() { const { default: chalk } = await import('chalk'); console.log(chalk.green('ok')); } main();
How to diagnose
- Package — Which package and version?
- Module type — package.json "type"? TS module setting?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- ERR unknown command Redis: (error) ERR unknown command 'JSON.GET', with args beginning with: / unknown command 'FT.SEARCH'
- ERR_IMPORT_ATTRIBUTE_MISSING TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module needs an import attribute of "type: json"
- ERR_PACKAGE_PATH_NOT_EXPORTED Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './x' is not defined by "exports"
Most viewed in Node.js
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 12 Oct 2026