Nextjs Fundamentals · Deployment & Operations

Static export and its limits

output: 'export'

Static export and its limits

If your app never needs a server, Next.js can compile it to plain HTML, CSS, and JavaScript — a static export. Set the output mode in next.config.js:

// next.config.js
module.exports = { output: 'export' };

Running next build writes an out folder of prerendered files that any static host — S3, Nginx, GitHub Pages — can serve. Server Components still run, but only at build time.

The trade-off is real: a static export disables every feature that needs a server. Server Actions, Route Handlers that read the request, ISR, dynamic rendering, Proxy, Draft Mode, and cookies() / headers() all stop working. Image Optimization is off too unless you supply a custom loader:

// next.config.js
module.exports = {
  output: 'export',
  images: { loader: 'custom', loaderFile: './my-loader.ts' },
};

Route Handlers are limited as well — only the GET verb renders, and only when you mark the handler force-static. Attempting a server-only feature errors during next build (or next dev).

So choose static export only when the content is fixed at build time. If you later need a mutation or per-request data, you must move back to a server target.

You are about to answer a short quiz on output: 'export'.

  1. A static export writes an out folder of prerendered HTML, CSS, and JS.
  2. Server Actions work in a static export.
  3. Static export is enabled by setting output to ___ in next.config.js.
  4. Incremental Static Regeneration (ISR) is not available in a static export.
  5. Image Optimization works in a static export with the default loader.
  6. Route Handlers in a static export support only the ___ HTTP verb.