Next.js: Error [ERR_REQUIRE_ESM]: require() of ES Module next.config.js / SyntaxError: Unexpected token 'export'
The config file uses ESM syntax in a CommonJS context (or the reverse), so Node can't load it.
Error [ERR_REQUIRE_ESM]: require() of ES Module next.config.jsSyntaxError: Unexpected token 'export' next.config.jsFailed to load next.config.jsnext.config.js: Cannot use import statement outside a moduleError: Cannot find module 'next.config.js' 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 defaultin next.config.js without "type": "module"module.exportsin an ESM project- Importing ESM-only packages from CJS config
- Mixed
importandrequire - Wrong file extension
⚡ Quick fix
- Rename to
next.config.mjsfor ESM - Or use CommonJS:
module.exports = nextConfig - Align
"type"in package.json with the syntax
Detailed fix by platform
Next.js
- tsx
// next.config.mjs const nextConfig = {}; export default nextConfig;
How to diagnose
- Syntax — ESM or CJS?
- Extension — .js/.mjs?
- type — package.json?
🔧 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
- Conflicting app and page file was found Next.js: ⨯ Conflicting app and page file was found, please remove the conflicting files to continue: "pages/index.tsx" - "app/page.tsx"
- CORS error calling Next.js API route / route handler Browser: Access to fetch at 'https://api.example.com/api/data' from origin 'https://app.example.com' has been blocked by CORS policy (Next.js route handler)
- ERR_IMPORT_ATTRIBUTE_MISSING TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module needs an import attribute of "type: json"
Most viewed in Next.js
- NEXT_REDIRECT Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)
- server-only Next.js: You're importing a component that needs "server-only". That only works in a Server Component
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
Other ways to find it
Where this error sits
Origin: On your device. 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 5 Nov 2026