next CLI
Learn how to run and build your application with the Next.js CLI.
The Next.js CLI allows you to develop, build, start your application, and more.
Basic usage:
Reference
The following options are available:
| Options | Description |
|---|---|
-h or --help | Shows all available options |
-v or --version | Outputs the Next.js version number |
Commands
The following commands are available:
| Command | Description |
|---|---|
dev | Starts Next.js in development mode with Hot Module Reloading, error reporting, and more. |
build | Creates an optimized production build of your application. Displaying information about each route. |
start | Starts Next.js in production mode. The application should be compiled with next build first. |
info | Prints relevant details about the current system which can be used to report Next.js bugs. |
telemetry | Allows you to enable or disable Next.js' completely anonymous telemetry collection. |
typegen | Generates TypeScript definitions for routes, pages, layouts, and route handlers without running a full build. |
Good to know: Running next without a command is an alias for next dev.
next dev options
next dev starts the application in development mode with Hot Module Reloading (HMR), error reporting, and more. The following options are available when running next dev:
| Option | Description |
|---|---|
-h, --help | Show all available options. |
[directory] | A directory in which to build the application. If not provided, current directory is used. |
--turbopack | Force enable Turbopack (enabled by default). Also available as --turbo. |
--webpack | Use Webpack instead of the default Turbopack bundler for development. |
-p or --port <port> | Specify a port number on which to start the application. Default: 3000, env: PORT |
-Hor --hostname <hostname> | Specify a hostname on which to start the application. Useful for making the application available for other devices on the network. Default: 0.0.0.0 |
--experimental-https | Starts the server with HTTPS and generates a self-signed certificate. |
--experimental-https-key <path> | Path to a HTTPS key file. |
--experimental-https-cert <path> | Path to a HTTPS certificate file. |
--experimental-https-ca <path> | Path to a HTTPS certificate authority file. |
--experimental-upload-trace <traceUrl> | Reports a subset of the debugging trace to a remote HTTP URL. |
next build options
next build creates an optimized production build of your application. The output displays information about each route. For example:
The following options are available for the next build command:
| Option | Description |
|---|---|
-h, --help | Show all available options. |
[directory] | A directory on which to build the application. If not provided, the current directory will be used. |
--turbopack | Force enable Turbopack (enabled by default). Also available as --turbo. |
--webpack | Build using Webpack. |
-d or --debug | Enables a more verbose build output. With this flag enabled additional build output like rewrites, redirects, and headers will be shown. |
--profile | Enables production profiling for React. |
--no-lint | Disables linting. Note: linting will be removed from next build in Next 16. If you're using Next 15.5+ with a linter other than eslint, linting during build will not occur. |
--no-mangling | Disables mangling. This may affect performance and should only be used for debugging purposes. |
--experimental-app-only | Builds only App Router routes. |
--experimental-build-mode [mode] | Uses an experimental build mode. (choices: "compile", "generate", default: "default") |
--debug-prerender | Debug prerender errors in development. |
--debug-build-paths=<patterns> | Build only specific routes for debugging. |
next start options
next start starts the application in production mode. The application should be compiled with next build first.
The following options are available for the next start command:
| Option | Description |
|---|---|
-h or --help | Show all available options. |
[directory] | A directory on which to start the application. If no directory is provided, the current directory will be used. |
-p or --port <port> | Specify a port number on which to start the application. (default: 3000, env: PORT) |
-H or --hostname <hostname> | Specify a hostname on which to start the application (default: 0.0.0.0). |
--keepAliveTimeout <keepAliveTimeout> | Specify the maximum amount of milliseconds to wait before closing the inactive connections. |
next info options
next info prints relevant details about the current system which can be used to report Next.js bugs when opening a GitHub issue. This information includes Operating System platform/arch/version, Binaries (Node.js, npm, Yarn, pnpm), package versions (next, react, react-dom), and more.
The output should look like this:
The following options are available for the next info command:
| Option | Description |
|---|---|
-h or --help | Show all available options |
--verbose | Collects additional information for debugging. |
next telemetry options
Next.js collects completely anonymous telemetry data about general usage. Participation in this anonymous program is optional, and you can opt-out if you prefer not to share information.
The following options are available for the next telemetry command:
| Option | Description |
|---|---|
-h, --help | Show all available options. |
--enable | Enables Next.js' telemetry collection. |
--disable | Disables Next.js' telemetry collection. |
Learn more about Telemetry.
next typegen Options
next typegen generates TypeScript definitions for your application's routes without performing a full build. This is useful for IDE autocomplete and CI type-checking of route usage.
Previously, route types were only generated during next dev or next build, which meant running tsc --noEmit directly wouldn't validate your route types. Now you can generate types independently and validate them externally:
The following options are available for the next typegen command:
| Option | Description |
|---|---|
-h, --help | Show all available options. |
[directory] | A directory on which to generate types. If not provided, the current directory will be used. |
Output files are written to <distDir>/types (typically: .next/dev/types or .next/types, see isolatedDevBuild):
Additionally, next typegen generates a next-env.d.ts file. We recommend adding next-env.d.ts to your .gitignore file.
The next-env.d.ts file is included into your tsconfig.json file, to make Next.js types available to your project.
To ensure next-env.d.ts is present before type-checking run next typegen. The commands next dev and next build also generate the next-env.d.ts file, but it is often undesirable to run these just to type-check, for example in CI/CD environments.
Good to know: next typegen loads your Next.js config (next.config.js, next.config.mjs, or next.config.ts) using the production build phase. Ensure any required environment variables and dependencies are available so the config can load correctly.
Examples
Debugging prerender errors
If you encounter prerendering errors during next build, you can pass the --debug-prerender flag to get more detailed output:
This enables several experimental options to make debugging easier:
- Disables server code minification:
experimental.serverMinification = falseexperimental.turbopackMinify = false
- Generates source maps for server bundles:
experimental.serverSourceMaps = true
- Enables source map consumption in child processes used for prerendering:
enablePrerenderSourceMaps = true
- Continues building even after the first prerender error, so you can see all issues at once:
experimental.prerenderEarlyExit = false
This helps surface more readable stack traces and code frames in the build output.
Warning: --debug-prerender is for debugging in development only. Do not deploy builds generated with --debug-prerender to production, as it may impact performance.
Building specific routes
You can build only specific routes in the App and Pages Routers using the --debug-build-paths option. This is useful for faster debugging when working with large applications. The --debug-build-paths option accepts comma-separated file paths and supports glob patterns:
Changing the default port
By default, Next.js uses http://localhost:3000 during development and with next start. The default port can be changed with the -p option, like so:
Or using the PORT environment variable:
Good to know: PORT cannot be set in .env as booting up the HTTP server happens before any other code is initialized.
Using HTTPS during development
For certain use cases like webhooks or authentication, you can use HTTPS to have a secure environment on localhost. Next.js can generate a self-signed certificate with next dev using the --experimental-https flag:
With the generated certificate, the Next.js development server will exist at https://localhost:3000. The default port 3000 is used unless a port is specified with -p, --port, or PORT.
You can also provide a custom certificate and key with --experimental-https-key and --experimental-https-cert. Optionally, you can provide a custom CA certificate with --experimental-https-ca as well.
next dev --experimental-https is only intended for development and creates a locally trusted certificate with mkcert. In production, use properly issued certificates from trusted authorities.
Configuring a timeout for downstream proxies
When deploying Next.js behind a downstream proxy (e.g. a load-balancer like AWS ELB/ALB), it's important to configure Next's underlying HTTP server with keep-alive timeouts that are larger than the downstream proxy's timeouts. Otherwise, once a keep-alive timeout is reached for a given TCP connection, Node.js will immediately terminate that connection without notifying the downstream proxy. This results in a proxy error whenever it attempts to reuse a connection that Node.js has already terminated.
To configure the timeout values for the production Next.js server, pass --keepAliveTimeout (in milliseconds) to next start, like so:
Passing Node.js arguments
You can pass any node arguments to next commands. For example:
| Version | Changes |
|---|---|
v16.0.0 | The JS bundle size metrics have been removed from next build |
v15.5.0 | Add the next typegen command |
v15.4.0 | Add --debug-prerender option for next build to help debug prerender errors. |