Skip to content
Latchkey

next build: Next.js Production Build

next build creates an optimized production build of a Next.js app in the .next directory, ready for next start or deployment.

next build is where a Next app is compiled, type-checked, linted, and pre-rendered. It is a strict gate: type or prerender failures stop the build.

What it does

next build compiles server and client bundles, runs TypeScript type checking and ESLint (unless disabled), and statically pre-renders eligible pages. Output goes to .next. It fails the build on type errors, lint errors, or errors thrown during static generation.

Common usage

Terminal
next build
# skip lint during build (run it separately)
next build --no-lint
# more diagnostic output
next build --debug

Options

FlagWhat it does
--no-lintSkip ESLint during the build
--debugVerbose build diagnostics
--profileEnable React production profiling
--turbopackBuild with Turbopack instead of webpack

In CI

Provide the same environment variables at build time that the app expects; values read at build must exist in the runner env or pages fail to generate. Cache the .next/cache directory between runs to keep incremental builds fast.

Common errors in CI

"Failed to compile" followed by "Type error: ..." means TypeScript checking failed during build. "Error occurred prerendering page \"/...\"" means code threw during static generation, often a fetch to a missing env-configured URL or a browser API used on the server. "You have ESLint errors" stops the build unless you use --no-lint. Large builds may hit "JavaScript heap out of memory" (raise NODE_OPTIONS).

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →