next.config.js: ES Module / require error Next.js Origin: On your device Last updated 5 Nov 2026

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.

Exact message you may see 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'
Seen on: Next.js Node.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 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?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

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" (Next.js)Conflicting app and p…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) (Next.js)CORS error calling Ne…ERR_IMPORT_ATTRIBUTE_MISSING — TypeError [ERR_IMPORT_ATTRIBUTE_MISSING]: Module needs an import attribute of "type: json" (Node.js)ERR_IMPORT_ATTRIBUTE_…ERR_REQUIRE_ESM — Error [ERR_REQUIRE_ESM]: require() of ES Module not supported (Node.js)ERR_REQUIRE_ESMERR_UNKNOWN_FILE_EXTENSION — TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" (Node.js)ERR_UNKNOWN_FILE_EXTE…Features not supported with output: export (headers, redirects, image loader) — Next.js: Specified "headers" cannot be used with "output: export" / Image Optimization using the default loader is not compatible with `{ output: 'export' }` (Next.js)Features not supporte…Invalid next.config.js options detected — Next.js: Invalid next.config.js options detected: Unrecognized key(s) in object: 'xyz' (Next.js)Invalid next.config.j…Jest ESM — Jest: SyntaxError: Cannot use import statement outside a module (Jest encountered an unexpected token) (React)Jest ESMnext.conf…

Explore the map of this error Full error map →

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