Configuration, Environments and Deployment
Know when each setting takes effect (build time vs request time), what a static export cannot do, and what multiple self-hosted instances must agree on.
Key points
- 1
NEXT_PUBLIC_values and the configenvoption are inlined duringnext build, in client and server code alike. Changing them later requires a rebuild. - 2
Variables are looked up in
process.env,.env.$(NODE_ENV).local,.env.local(skipped in test),.env.$(NODE_ENV), then.env. The first match wins. - 3
Server code that must read env at runtime should render dynamically, for example after
await connection().serverRuntimeConfigandpublicRuntimeConfigwere removed in 16. - 4
output: 'standalone'emits a minimalserver.jsconfigured byPORTandHOSTNAME. Copypublicand.next/staticyourself, and setoutputFileTracingRootin monorepos. - 5
output: 'export'writes toout/and drops server features: Server Actions, Proxy, cookies, rewrites, redirects, headers, ISR, Draft Mode and default image optimization. - 6
Multiple instances need the same
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY, the samedeploymentIdper deployment, and a shared cache handler with tag coordination. - 7
Next.js 16 requires Node.js 20.9+, uses Turbopack by default (a found
webpackconfig fails the build), removesnext lint, and renames middleware to Node.js-onlyproxy.
Common traps
Restarting a container with a new
NEXT_PUBLIC_*value changes nothing in browsers; the old value is baked into the bundle.typescript.ignoreBuildErrorsskips type checking entirely, so runtsc --noEmitseparately.A
$in a.envvalue starts a variable reference; escape it as\$to keep it literal.
Read the source
Test yourself on Configuration, Environments and Deployment
Ten questions, with the answer and explanation after each one.