# Next.js: Error [ERR_REQUIRE_ESM]: require() of ES Module next.config.js / SyntaxError: Unexpected token 'export'

**Code:** `next.config.js: ES Module / require error` · **Category:** Next.js · **Seen on:** Next.js, Node.js

The config file uses ESM syntax in a CommonJS context (or the reverse), so Node can't load it.

## Meaning

Use `module.exports = {}` in `.js` (CJS) or rename to `next.config.mjs` and use `export default`. If `package.json` has `"type": "module"`, `.js` is ESM and `require`/`module.exports` fail. Next 15 also supports `next.config.ts`.

## Common causes

- `export default` in next.config.js without "type": "module"
- `module.exports` in an ESM project
- Importing ESM-only packages from CJS config
- Mixed `import` and `require`
- Wrong file extension

## Quick fix

1. Rename to `next.config.mjs` for ESM
2. Or use CommonJS: `module.exports = nextConfig`
3. Align `"type"` in package.json with the syntax

## Detailed fix by platform

### Next.js

1. 

```tsx
// next.config.mjs
const nextConfig = {};
export default nextConfig;
```


## How to diagnose

1. **Syntax** — ESM or CJS?
2. **Extension** — .js/.mjs?
3. **type** — package.json?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nextjs/next-config-esm-require-error)
