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
output: "export"in config.next buildprerenders every route to HTML plus the RSC payload files used for client navigation.- Dynamic routes must list every path in
generateStaticParams. - 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
GETresponses (generated as files, such asfeed.xml). - Metadata, sitemaps, robots, generated OG images.
next/imagewith a customloaderorimages.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(),searchParamson the server.- ISR,
revalidatePath/revalidateTag, Draft Mode. - Dynamic routes without
generateStaticParams,dynamicParams: true. - Default image optimization and internationalized routing config.
Tips
trailingSlash: trueproduces/about/index.html, which many static hosts need.basePathfor hosting under a subpath (GitHub Pages project sites).- Use a backend or serverless functions elsewhere for forms.
Code example
tsx
1// next.config.ts2import type { NextConfig } from "next";34const nextConfig: NextConfig = {5 output: "export", // replaces the removed `next export` command6 trailingSlash: true, // out/about/index.html7 basePath: "/docs-site", // e.g. GitHub Pages project8 images: { unoptimized: true },9};10export default nextConfig;1112// app/blog/[slug]/page.tsx - every path must be known at build time13// export const dynamicParams = false;14// export async function generateStaticParams() {15// const posts = await getAllPosts();16// return posts.map((p) => ({ slug: p.slug }));17// }1819// package.json20// "build": "next build" -> static files in ./out21// "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.