> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/vercel/next.js/llms.txt
> Use this file to discover all available pages before exploring further.

# next build

> Build your Next.js application for production with next build.

`next build` creates an optimized production build of your application. The output shows a summary of each route:

```bash theme={null}
Route (app)
┌ ○ /_not-found
└ ƒ /products/[id]

○  (Static)   prerendered as static content
ƒ  (Dynamic)  server-rendered on demand
```

## Usage

```bash theme={null}
next build [directory] [options]
```

## Options

<ParamField path="[directory]" type="string">
  The directory containing the Next.js application. Defaults to the current working directory.
</ParamField>

<ParamField path="--turbopack" type="boolean">
  Force Turbopack (the default bundler). Also available as `--turbo`.
</ParamField>

<ParamField path="--webpack" type="boolean">
  Build using Webpack instead of the default Turbopack.
</ParamField>

<ParamField path="-d / --debug" type="boolean">
  Enable verbose build output. Shows rewrites, redirects, and headers configuration.
</ParamField>

<ParamField path="--profile" type="boolean">
  Enable production [React profiling](https://react.dev/reference/react/Profiler). Adds a small overhead.
</ParamField>

<ParamField path="--no-lint" type="boolean">
  Disable linting during the build.
</ParamField>

<ParamField path="--no-mangling" type="boolean">
  Disable [name mangling](https://en.wikipedia.org/wiki/Name_mangling). Reduces performance; use only for debugging.
</ParamField>

<ParamField path="--experimental-app-only" type="boolean">
  Build only App Router routes, skipping Pages Router routes.
</ParamField>

<ParamField path="--experimental-build-mode [mode]" type="string" default="default">
  Use an experimental build mode. Choices: `'compile'`, `'generate'`, `'default'`.
</ParamField>

<ParamField path="--experimental-analyze" type="boolean">
  Analyze bundle output using the bundle explorer. Only compatible with the Turbopack bundler.
</ParamField>

<ParamField path="--experimental-debug-memory-usage" type="boolean">
  Enable memory profiling features to help debug memory consumption during the build.
</ParamField>

<ParamField path="--experimental-upload-trace <traceUrl>" type="string">
  Report a subset of the debugging trace to a remote HTTP URL. Includes sensitive data.
</ParamField>

<ParamField path="--experimental-next-config-strip-types" type="boolean">
  Use Node.js native TypeScript resolution for `next.config.ts` or `next.config.mts`.
</ParamField>

<ParamField path="--debug-prerender" type="boolean">
  Debug prerender errors in a development-like build. Do not deploy builds produced with this flag.
</ParamField>

<ParamField path="--debug-build-paths <patterns>" type="string">
  Build only specific routes (comma-separated file paths or globs). Useful for faster targeted debugging.
</ParamField>

<ParamField path="--experimental-cpu-prof" type="boolean">
  Enable CPU profiling via V8's inspector. Profiles are saved to `.next/cpu-profiles/` on process exit.
</ParamField>

<ParamField path="-h / --help" type="boolean">
  Show all available options.
</ParamField>

## Build output analysis

The build output shows route types and sizes. To analyze bundle composition in detail, use the `--experimental-analyze` flag with Turbopack:

```bash theme={null}
next build --experimental-analyze
```

This runs a Turbopack build and opens an interactive bundle explorer in the browser.

## Standalone output

To produce a self-contained deployment artifact, set `output: 'standalone'` in `next.config.js`:

```js next.config.js theme={null}
module.exports = {
  output: 'standalone',
}
```

After running `next build`, copy static assets and start the server:

```bash theme={null}
cp -r public .next/standalone/ && cp -r .next/static .next/standalone/.next/
node .next/standalone/server.js
```

## Build traces

Next.js generates `.nft.json` trace files in `.next/` that list all files required by each route. These are used by `output: 'standalone'` to create a minimal deployment bundle.

## Examples

### Debug prerender errors

```bash theme={null}
next build --debug-prerender
```

This disables minification, enables server source maps, and continues past the first prerender error to surface all issues at once.

<Warning>
  Do not deploy builds created with `--debug-prerender`—they may have reduced performance.
</Warning>

### Build specific routes

```bash theme={null}
# Single route
next build --debug-build-paths="app/page.tsx"

# Multiple routes
next build --debug-build-paths="app/page.tsx,pages/index.tsx"

# Glob patterns
next build --debug-build-paths="app/**/page.tsx"
```

### CPU profiling

```bash theme={null}
next build --experimental-cpu-prof
```

For Turbopack builds, profiles are named:

* `build-main-*` — main orchestration process
* `build-turbopack-*` — Turbopack compilation worker

For Webpack builds:

* `build-main-*` — main orchestration process
* `build-webpack-client-*` — client bundle worker
* `build-webpack-server-*` — server bundle worker
* `build-webpack-edge-server-*` — edge runtime worker

## Version history

| Version   | Changes                                                                      |
| --------- | ---------------------------------------------------------------------------- |
| `v16.0.0` | Turbopack is the default bundler; JS bundle size metrics removed from output |
| `v15.5.0` | Turbopack `build` support in beta                                            |
| `v15.4.0` | `--debug-prerender` flag added                                               |
