Skip to content
Draft
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
fd7612a
docs: add Getting Started > Building guide
aurorascharff Apr 8, 2026
831b82f
docs: fix build output symbols and improve error explanation
aurorascharff Apr 8, 2026
5647664
docs: add partialFallbacks section for high-cardinality routes
aurorascharff Apr 8, 2026
78b6afb
docs: link to blocking-route error reference instead of inline list
aurorascharff Apr 8, 2026
6f68674
docs: clarify params error requires missing generateStaticParams
aurorascharff Apr 8, 2026
671c577
docs: tighten Step 3 prerender error section
aurorascharff Apr 8, 2026
5009157
docs: link Suspense references to streaming guide
aurorascharff Apr 8, 2026
0eeecff
docs: clarify generateStaticParams doesn't guarantee fully static
aurorascharff Apr 8, 2026
f0d6085
docs: fix generateStaticParams output, routes stay PPR
aurorascharff Apr 8, 2026
200846f
docs: clarify prerender behavior depends on route content
aurorascharff Apr 8, 2026
c4e4164
docs: clarify PPR symbol persists even when fully cached
aurorascharff Apr 8, 2026
9efedb1
docs: simplify generateStaticParams result explanation
aurorascharff Apr 8, 2026
a8094bf
docs: fix unknown params have no shell without partialFallbacks
aurorascharff Apr 8, 2026
809bcc1
docs: clean up generateStaticParams result paragraphs
aurorascharff Apr 8, 2026
82fe8c1
docs: params are resolved ahead of time, not fully prerendered
aurorascharff Apr 8, 2026
1f4b084
docs: unlisted params resolve without a fallback
aurorascharff Apr 8, 2026
a3a5b83
docs: move building guide from getting-started to guides
aurorascharff Apr 8, 2026
0de0823
docs: link first Suspense mention to React docs, second to streaming …
aurorascharff Apr 8, 2026
07b22be
docs: mention loading.js alongside Suspense as fix
aurorascharff Apr 8, 2026
48e8e66
docs: add --debug-build-paths section for building specific routes
aurorascharff Apr 8, 2026
1ab0a5a
docs: add 'What next build does' overview section
aurorascharff Apr 8, 2026
5fe50e6
docs: replace inline fix list with link to blocking-route reference
aurorascharff Apr 8, 2026
b63af2d
docs: add starter code snippet to Example section
aurorascharff Apr 8, 2026
3dba9f1
docs: add related frontmatter and match guide format
aurorascharff Apr 8, 2026
f9f21e8
docs: remove starter snippet that would fail at build time
aurorascharff Apr 8, 2026
7eccc7b
docs: restructure guide to start with the problem
aurorascharff Apr 8, 2026
ae2672d
docs: move Cache Components explanation before the example
aurorascharff Apr 8, 2026
b462a91
docs: remove forward reference to partialFallbacks
aurorascharff Apr 8, 2026
8f14e1d
docs: add cross-references to building guide
aurorascharff Apr 8, 2026
928d1f4
docs: link to building guide from deploying page
aurorascharff Apr 8, 2026
e843778
docs: restore original build output link in caching page
aurorascharff Apr 8, 2026
ad51e62
docs: add build and deploy mention to installation page
aurorascharff Apr 8, 2026
706a4d1
docs: move building guide link after the example block
aurorascharff Apr 8, 2026
22776ad
Update
aurorascharff Apr 8, 2026
9e49f38
Update for new build output
aurorascharff Apr 8, 2026
fe14199
Update
aurorascharff Apr 8, 2026
abb7a32
Update
aurorascharff Apr 8, 2026
707e936
Update
aurorascharff Apr 8, 2026
2498a25
Update writing style
aurorascharff Apr 8, 2026
a241b7a
Restructure guide
aurorascharff Apr 8, 2026
0a76393
Update
aurorascharff Apr 8, 2026
155c741
Update
aurorascharff Apr 8, 2026
cc34f9c
Update docs/01-app/02-guides/building.mdx
aurorascharff Apr 8, 2026
8e3e965
docs: align Building guide route tree with actual next build output
aurorascharff Apr 9, 2026
4047972
docs: refine Building guide (style, switchers, default-first flow)
aurorascharff Apr 9, 2026
e42357a
docs: clarify Building guide route tree explanation
aurorascharff Apr 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/01-app/01-getting-started/01-installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ export default function Page() {
2. Visit `http://localhost:3000` to view your application.
3. Edit the <AppOnly>`app/page.tsx`</AppOnly><PagesOnly>`pages/index.tsx`</PagesOnly> file and save it to see the updated result in your browser.

When you're ready for production, run `npm run build` to [build your application](/docs/app/guides/building), then `npm run start` to start the server. Learn more about [deploying](/docs/app/getting-started/deploying).

## Set up TypeScript

> Minimum TypeScript version: `v5.1.0`
Expand Down
2 changes: 1 addition & 1 deletion docs/01-app/01-getting-started/17-deploying.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Next.js can be deployed to any provider that supports Node.js. Ensure your `pack
}
```

Then, run `npm run build` to build your application and `npm run start` to start the Node.js server. This server supports all Next.js features. If needed, you can also eject to a [custom server](/docs/app/guides/custom-server).
Then, run `npm run build` to [build your application](/docs/app/guides/building) and `npm run start` to start the Node.js server. This server supports all Next.js features. If needed, you can also eject to a [custom server](/docs/app/guides/custom-server).

Node.js deployments support all Next.js features. Learn how to [configure them](/docs/app/guides/self-hosting) for your infrastructure.

Expand Down
188 changes: 188 additions & 0 deletions docs/01-app/02-guides/building.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
---
title: Building your application
description: Learn what happens when you run next build, how to read the build output, and how to fix common prerender errors.
nav_title: Building
related:
description: Related API references and guides.
links:
- app/api-reference/cli/next
- app/api-reference/functions/generate-static-params
- app/api-reference/config/next-config-js/cacheComponents
- app/guides/streaming
- app/guides/public-static-pages
- app/guides/ci-build-caching
---

When your application is ready for production, `next build` compiles it into optimized bundles and prerendered pages. The build output shows how each route will be served: fully static or partially prerendered.

This guide will show you how to read the build output, pre-render dynamic routes, and fix common build errors.

## What `next build` does

Running `next build` goes through these phases:

1. **Setup.** Loads [environment variables](/docs/app/guides/environment-variables) (`.env` files), validates your [`next.config`](/docs/app/api-reference/config/next-config-js), and generates a [build ID](/docs/app/api-reference/config/next-config-js/generateBuildId).
2. **Route discovery.** Scans `app/` and `pages/` directories for routes, middleware, and [instrumentation](/docs/app/api-reference/file-conventions/instrumentation) hooks. Generates TypeScript route definitions.
3. **Compilation.** Bundles client, server, and edge code with [Turbopack](/docs/app/api-reference/turbopack) (or Webpack). Transpiles TypeScript and JSX, tree-shakes unused code, and optimizes CSS and fonts. Type checking runs in parallel.
4. **Static analysis.** Classifies each route as static or partially prerendered. Collects [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params) output. Checks for [prerender-blocking errors](/docs/messages/blocking-route).
5. **Prerendering.** Prerenders static pages and PPR shells to HTML. Generates [RSC payloads](/docs/app/getting-started/server-and-client-components#on-the-server) for client-side navigation.
6. **Output.** Writes the final build to `.next/`. For [`output: 'standalone'`](/docs/app/guides/self-hosting), bundles only the files needed at runtime. For [`output: 'export'`](/docs/app/guides/static-exports), generates a full static site. Prints the route table.

## Prerendering with Cache Components

With [Cache Components](/docs/app/api-reference/config/next-config-js/cacheComponents), Next.js prerenders as much of each route as possible at build time. Components that depend on request-time data (such as `params`, `searchParams`, `cookies()`, or `headers()`) can't be resolved ahead of time. Next.js requires you to explicitly handle these with [`<Suspense>`](/docs/app/guides/streaming) or [`'use cache'`](/docs/app/api-reference/directives/use-cache). If you don't, the build fails with a [prerender-blocking error](/docs/messages/blocking-route).

Every route in the build output is either fully static (`○`) or partially prerendered (`◐`). [Partial Prerendering](/docs/app/getting-started/caching#how-rendering-works) is the default rendering model. The static parts are served instantly from a CDN. The dynamic parts stream in at request time.

## Example

As an example, we'll work with a product catalog. We have a dynamic detail page at `/products/[id]` that fetches product data:

```tsx filename="app/products/[id]/page.tsx"
export default async function Page({ params }) {
const { id } = await params
const product = await db.product.find(id)
return <div>{product.name}</div>
}
```

If we run `next build`, this fails:

```txt filename="Terminal"
Uncached data, `params`, `searchParams`, or `connection()` was accessed outside of `<Suspense>`.
This delays the entire page from rendering, resulting in a slow user experience.
```

The param values are not known at build time, so Next.js can't prerender the page. We need to tell it how to handle the dynamic data. See the [blocking-route error reference](/docs/messages/blocking-route) for a full list of triggers and fixes.

#### Debugging prerender errors

If the error doesn't point to the exact line, use `--debug-prerender`:

```bash filename="Terminal"
next build --debug-prerender
```

This disables minification and enables source maps for server bundles, producing readable stack traces that show which function triggered the error. It also continues past the first error so you can see all issues at once.

> **Warning:** Do not deploy builds generated with `--debug-prerender`. It disables optimizations needed for production performance.

In large applications, you can build only specific routes using `--debug-build-paths` to speed up debugging:

```bash filename="Terminal"
next build --debug-build-paths="app/products/[id]/page.tsx"
```

This accepts comma-separated file paths and glob patterns. See [`--debug-build-paths`](/docs/app/api-reference/cli/next#building-specific-routes) for more details.

### Step 1: Resolve params with `generateStaticParams`

The most direct fix is telling Next.js which param values exist. Export [`generateStaticParams`](/docs/app/api-reference/functions/generate-static-params) to resolve them at build time:

```tsx filename="app/products/[id]/page.tsx"
export async function generateStaticParams() {
const products = await db.product.findMany()
return products.map((product) => ({ id: product.id }))
}

export default async function Page({ params }) {
const { id } = await params
const product = await db.product.find(id)
return <div>{product.name}</div>
}
```

Now `next build` succeeds and prints the route table:

```bash filename="Terminal"
Route (app)
┌ ○ /
├ ○ /_not-found
├ /products/[id]
│ ├ ○ /products/1
│ ├ ○ /products/2
│ └ ○ [+4 more paths]

○ (Static) prerendered as static content
◐ (Partial Prerender) prerendered as static HTML with dynamic server-streamed content
```

Each symbol tells you how a route is served:

| Symbol | Name | Behavior |
| ------ | ----------------- | ------------------------------------------------------------------------- |
| `○` | Static | Fully prerendered at build time. Served from CDN with no server work. |
| `◐` | Partial Prerender | Static shell served from CDN. Dynamic content streams in at request time. |

The listed params are resolved ahead of time. Each one shows its own symbol — `○` if the page is fully static, or `◐` if it contains streamed content. Unlisted params (for example, `/products/99`) are server-rendered on the first request and the page has to resolve entirely without a fallback. After the first visit, the result is cached.

> **Good to know:** `generateStaticParams` must return at least one param. An empty array causes a [build error](/docs/messages/empty-generate-static-params).

### Step 2: Stream dynamic content with Suspense

Sometimes you can't provide all param values ahead of time, or the page has content that depends on the request (cookies, headers). In these cases, [stream](/docs/app/guides/streaming) the dynamic content with [`<Suspense>`](https://react.dev/reference/react/Suspense), or add a [`loading.js`](/docs/app/api-reference/file-conventions/loading) file:

```tsx filename="app/products/[id]/page.tsx"
import { Suspense } from 'react'

export default function Page({ params }) {
return (
<Suspense fallback={<ProductSkeleton />}>
<ProductContent params={params} />
</Suspense>
)
}

async function ProductContent({ params }) {
const { id } = await params
const product = await db.product.find(id)
return <div>{product.name}</div>
}
```

The fallback is prerendered into the static shell. The content streams in at request time:

```bash filename="Terminal"
Route (app)
┌ ○ /
├ ○ /_not-found
├ /products/[id]
│ ├ ◐ /products/1
│ ├ ◐ /products/2
│ └ ◐ [+4 more paths]
```

The routes now show `◐` (Partial Prerender) because each page has a static shell with dynamic content that streams in at request time.

You can combine both approaches: use `generateStaticParams` for known params and `<Suspense>` for dynamic content within the page.

#### High-cardinality routes

For sites with many possible slugs (e-commerce with millions of products, user-generated content), pre-rendering every page at build time is not practical.

The experimental [`partialFallbacks`](/docs/app/api-reference/config/next-config-js/partialFallbacks) flag serves an instant `<Suspense>` shell from CDN for unknown slugs while the dynamic data streams in. After the first visit, the page is cached and upgraded to a fully static version.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO cc @icyJoseph create this docpage


```ts filename="next.config.ts"
import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
cacheComponents: true,
experimental: {
partialFallbacks: true,
},
}

export default nextConfig
```

This means you can keep `generateStaticParams` small and let traffic determine which additional pages get cached.

### Next steps

You now know how to read the build output, pre-render dynamic routes, and fix prerender errors.

Next, learn how to:

- [Deploy your application](/docs/app/getting-started/deploying)
- [Cache data and UI](/docs/app/getting-started/caching)
- [Configure CI build caching](/docs/app/guides/ci-build-caching)
2 changes: 2 additions & 0 deletions docs/01-app/03-api-reference/06-cli/next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Route (app)
ƒ (Dynamic) server-rendered on demand
```

See the [Building guide](/docs/app/guides/building) to learn how to read the output, pre-render dynamic routes, and debug build errors.

The following options are available for the `next build` command:

| Option | Description |
Expand Down
Loading