# Error: next.config.js must use CommonJS module syntax (module.exports = ...) or be a valid ESM export.

- **ID:** `nextjs/invalid-runtime-config-cjs`
- **Domain:** nextjs
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

Next.js loads next.config.js with Node.js require(), which expects CommonJS exports. Using ES module syntax like export default or export const without proper configuration causes a parse error.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 13.0.0 | active | — | — |
| 13.5.0 | active | — | — |
| 14.0.0 | active | — | — |
| 14.2.0 | active | — | — |
| 15.0.0 | active | — | — |

## Workarounds

1. **Change next.config.js to use CommonJS syntax: /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true }; module.exports = nextConfig;** (95% success)
   ```
   Change next.config.js to use CommonJS syntax: /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true }; module.exports = nextConfig;
   ```
2. **If you prefer ESM, rename the file to next.config.mjs and use export default; Next.js 14+ supports .mjs extension for ESM configs.** (90% success)
   ```
   If you prefer ESM, rename the file to next.config.mjs and use export default; Next.js 14+ supports .mjs extension for ESM configs.
   ```

## Dead Ends

- **Adding 'type': 'module' to package.json and using ESM syntax in next.config.js** — Next.js does not support ESM for next.config.js even if the package.json has type:module. It always expects CommonJS. (100% fail)
- **Using export default function nextConfig() { ... } which is valid ESM but not CommonJS** — Node.js require() cannot interpret export default; it expects module.exports = ... (95% fail)
