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…).
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 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026