Next.jsMedium

What is the output option in next.config.js (standalone, export)?

output controls what next build produces. The default emits a .next folder run with next start. output: "standalone" creates a minimal self-contained server in .next/standalone with only the needed node_modules, ideal for Docker. output: "export" writes a fully static site to out/ that any static host can serve, without server features.

Default

next build then next start on a Node.js server; all features available.

"standalone"

  • Uses output file tracing to copy only the files and dependencies each route needs.
  • Generates .next/standalone/server.js; run it with node server.js.
  • Copy public/ and .next/static/ into the standalone folder yourself (or serve them from a CDN).
  • Typical Docker images shrink from 1GB+ to around 100-200MB.
  • In monorepos set outputFileTracingRoot to the repo root.
  • Supports all server features: ISR, Cache Components, Server Functions, Proxy, image optimization.

"export"

  • Static HTML, CSS and JS in out/.
  • Works: Server Components rendered at build time, static Route Handlers (GET without request data), client-side data fetching, next/image with a custom loader or unoptimized.
  • Not supported: Server Functions, Proxy, cookies and headers, ISR and revalidation, dynamic routes without generateStaticParams, rewrites, redirects, headers config, default image optimization, and dynamicParams: true.
  • Replaced the old next export command, removed in Next.js 14.

Choosing

  • Docker, Kubernetes, VMs: standalone.
  • Static hosting, GitHub Pages, S3 + CloudFront, or embedding in another app: export.
  • Vercel and other adapter-based platforms: default (they use the Adapters API, stable in 16.2).

Code example

tsx
1// next.config.ts
2import type { NextConfig } from "next";
3
4const nextConfig: NextConfig = {
5 output: "standalone", // or "export" for a static site
6};
7export default nextConfig;
8
9// Dockerfile (standalone)
10// FROM node:22-alpine AS build
11// WORKDIR /app
12// COPY . .
13// RUN npm ci && npm run build
14//
15// FROM node:22-alpine
16// WORKDIR /app
17// ENV NODE_ENV=production PORT=3000 HOSTNAME=0.0.0.0
18// COPY --from=build /app/.next/standalone ./
19// COPY --from=build /app/.next/static ./.next/static
20// COPY --from=build /app/public ./public
21// EXPOSE 3000
22// CMD ["node", "server.js"]

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app