Next.jsMedium

How does next export work and what are its limitations?

The next export command was removed in Next.js 14. Static export is now done by setting output: "export" in next.config.ts and running next build, which writes plain HTML, CSS and JavaScript to out/. The result runs on any static host but has no Node.js server, so request-time features are unavailable.

How it works now

  1. output: "export" in config.
  2. next build prerenders every route to HTML plus the RSC payload files used for client navigation.
  3. Dynamic routes must list every path in generateStaticParams.
  4. Deploy out/ to S3, Netlify, GitHub Pages, Nginx, or any CDN.

What still works

  • Server Components (rendered at build time).
  • Client Components and client-side data fetching (SWR, TanStack Query).
  • <Link> client navigation and prefetching.
  • Route Handlers with static GET responses (generated as files, such as feed.xml).
  • Metadata, sitemaps, robots, generated OG images.
  • next/image with a custom loader or images.unoptimized: true.

What does not

  • Server Functions and form actions.
  • Proxy (middleware), rewrites, redirects and custom headers from config (configure them on your host).
  • cookies(), headers(), searchParams on the server.
  • ISR, revalidatePath/revalidateTag, Draft Mode.
  • Dynamic routes without generateStaticParams, dynamicParams: true.
  • Default image optimization and internationalized routing config.

Tips

  • trailingSlash: true produces /about/index.html, which many static hosts need.
  • basePath for hosting under a subpath (GitHub Pages project sites).
  • Use a backend or serverless functions elsewhere for forms.

Code example

tsx
1// next.config.ts
2import type { NextConfig } from "next";
3
4const nextConfig: NextConfig = {
5 output: "export", // replaces the removed `next export` command
6 trailingSlash: true, // out/about/index.html
7 basePath: "/docs-site", // e.g. GitHub Pages project
8 images: { unoptimized: true },
9};
10export default nextConfig;
11
12// app/blog/[slug]/page.tsx - every path must be known at build time
13// export const dynamicParams = false;
14// export async function generateStaticParams() {
15// const posts = await getAllPosts();
16// return posts.map((p) => ({ slug: p.slug }));
17// }
18
19// package.json
20// "build": "next build" -> static files in ./out
21// "preview": "npx serve out"

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