next.config.js (or next.config.ts) file in the root of your project, alongside package.json.
next.config.js is a Node.js module, not a JSON file. It is used by the Next.js server and build phases and is not included in the browser bundle. Use next.config.mjs for ECMAScript module syntax, or next.config.ts for TypeScript.File formats
ESM (next.config.mjs)
ESM (next.config.mjs)
next.config.mjs
Function form
Function form
You can export a function that receives the current phase and default config:
next.config.js
Async function form
Async function form
next.config.js
Output
Controls how Next.js outputs the built application.Sets the output mode for the build. Accepted values:
'standalone' or 'export'.'standalone'
Creates a self-contained .next/standalone folder that includes only the files needed for production deployment. A minimal server.js is generated that can replace next start.
next.config.js
The
public and .next/static directories are not copied automatically—copy them manually after build:'export'
Generates a fully static HTML export to the out/ directory. No Node.js server is required.
next.config.js
Output file tracing
For monorepos, setoutputFileTracingRoot to include files from parent directories:
next.config.js
Images
Configuration for the built-in image optimization API used by
next/image.Remote patterns
next.config.js
Allowlist of remote image sources. Each entry can specify
protocol, hostname, port, and pathname glob.Legacy allowlist of hostnames. Prefer
remotePatterns for more precise control.Sizes and formats
next.config.js
Breakpoints used to generate
srcset values for device widths.Additional image widths used when the
sizes prop is provided.Accepted MIME types for image optimization. Set to
['image/avif', 'image/webp'] to enable AVIF.Minimum cache TTL in seconds for optimized images.
Allow serving SVG images from the optimization endpoint. Ensure
contentSecurityPolicy is also set.Custom loader
next.config.js
Redirects
Redirects an incoming request path to a different destination path. Returns an array of redirect objects.next.config.js
Incoming request path pattern. Supports named parameters (
:slug), wildcards (:slug*), and regex.The path to redirect to. Named parameters captured in
source can be referenced here.When
true, uses HTTP 308 (permanent, cached by clients). When false, uses HTTP 307 (temporary).Array of conditions based on headers, cookies, or query params that must be present for the redirect to apply.
Array of conditions that must NOT be present for the redirect to apply.
Set to
false to exclude the basePath prefix from matching.Conditional redirects
next.config.js
Rewrites
Rewrites map an incoming request path to a different destination path without changing the URL visible to the user.next.config.js
rewrites can return an object with beforeFiles, afterFiles, and fallback arrays:
next.config.js
Headers
Set custom HTTP response headers for matching paths.next.config.js
Incoming request path pattern.
Array of
{ key, value } objects to set on matching responses.Environment variables
Inline build-time environment variables into the JavaScript bundle.next.config.js
process.env.customKey is replaced with 'my-value' at build time.
Variables set here are always inlined into the bundle. For runtime environment variables (not inlined), use
.env files with the NEXT_PUBLIC_ prefix or server-side access.TypeScript config
Skip TypeScript type-checking during
next build. Useful for CI pipelines where type-checking runs separately.Path to a custom
tsconfig.json file, relative to the project root.next.config.ts
ESLint config
next lint and the eslint option in next.config.js were removed in Next.js 16. Use the ESLint CLI directly.Webpack customization
Extend the webpack configuration used by Next.js. The function is called three times: once for the client bundle and twice for server-side bundles (Node.js and Edge runtimes).next.config.js
| Property | Type | Description |
|---|---|---|
buildId | string | Unique identifier for the current build |
dev | boolean | true when compiling in development mode |
isServer | boolean | true for server-side compilation |
nextRuntime | string | undefined | 'edge' or 'nodejs' for server; undefined for client |
defaultLoaders.babel | object | Default babel-loader configuration |
reactStrictMode
Enables React Strict Mode for the entire application. Useful for surfacing potential issues in your components during development.
next.config.js
poweredByHeader
When
false, removes the X-Powered-By: Next.js HTTP response header.next.config.js
basePath
Deploy the Next.js application under a sub-path of a domain. All page routes and static assets are automatically prefixed.
next.config.js
next/link and next/router will automatically use the configured basePath. Prefix external links manually.
trailingSlash
When
true, URLs without a trailing slash are redirected to their trailing-slash equivalent (e.g. /about → /about/).next.config.js
assetPrefix
Prefix for all static asset URLs. Use this to serve assets from a CDN.
next.config.js
experimental
Theexperimental object exposes features that are still in development. These options are subject to change and may be removed without a major version bump.
next.config.js
Other options
compress
compress
Enable gzip compression for rendered content and static files when using
next start. Has no effect if you use a reverse proxy that already handles compression.distDir
distDir
Change the build output directory.
next.config.js
generateEtags
generateEtags
pageExtensions
pageExtensions
Extensions recognized as pages or layouts.
next.config.js
serverExternalPackages
serverExternalPackages
Opt specific packages out of server-component bundling so they use native
require().next.config.js
transpilePackages
transpilePackages
Automatically transpile and bundle packages from
node_modules.next.config.js
Version history
| Version | Changes |
|---|---|
v15.0.0 | next.config.ts support added |
v13.0.0 | App Router introduced |
v12.1.0 | Async configuration function supported |
