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

**Code:** `ERR_REQUIRE_ESM` · **Category:** Node.js · **Seen on:** Node.js, npm

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

1. Switch the project to ESM (`"type": "module"`) and use `import`
2. Or use dynamic import: `const { default: fetch } = await import('node-fetch')`
3. Or pin the last CommonJS version of the package
4. Node 18+: use the built-in `fetch` instead of node-fetch

## Detailed fix by platform

### Node.js

1. 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

1. **Package** — Which package and version?
2. **Module type** — package.json "type"? TS module setting?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nodejs/err-require-esm)
