Configuration lifecycle
What you need to know
Next.js configuration controls the framework build and server behavior. Some settings are embedded into the generated application and cannot be changed by editing an environment variable after the build.
By the end, you can: distinguish build and runtime configuration; identify version-gated options.
Mount an application under a path in next.config.ts
import type { NextConfig } from 'next';const config: NextConfig = { basePath: '/books', trailingSlash: false };export default config;Expected behavior: A normal internal /catalog link through Next Link should target /books/catalog. Changing the base path requires rebuilding. This is a separate configuration example, not the root-mounted fixture.
How it works
Use next.config.ts for typed settings, next.config.mjs for ESM JavaScript, or the documented next.config.js form matching the project module format. A config function may select options based on a phase; async config is also supported where documented. Separate public build values from server-only runtime configuration. basePath sets the application mount path and is compiled into client bundles; assetPrefix primarily affects framework static assets used with a CDN and is not a substitute for mounting at /books. A public file still needs an appropriate URL and deployment plan. trailingSlash selects a canonical slash convention. output changes deployment artifact requirements; image and experimental options must be checked against the selected release and adapter. NEXT_PUBLIC_ values accessed through normal static references are inlined at build; values under next.config env are also exposed and must not contain secrets. Nonpublic variables can be read in request-time server code, but reading during prerender can capture a build-time value. Configuration typechecking is not proof of correct deployment.
Classify settings by evaluation boundary
basePath=/books -> rebuild if changedNEXT_PUBLIC_SITE_LABEL=River Books -> browser-visible build valueServer-only inventory setting read on each request -> runtime value if actually read thereassetPrefix -> framework asset delivery policyExpected behavior: A promoted build keeps the public values that were inlined when it was produced.
Common mistake
Do not put passwords in the env configuration or a NEXT_PUBLIC_ variable. Do not assume changing a build-time option at container startup rewrites existing client bundles.
Practice and verification
Prepare two deployment configurations, root-mounted and /books-mounted. List expected page, image and static asset paths. Check the actual build, generated HTML and deployment requests before approval.
Scope: Proposed Next.js 16.x, React 19, Node runtime. Root-mounted Pages and mixed-router fixtures with Cache Components disabled; the basePath example is separate. Framework examples are staged, not executed. Exact patched dependencies and platform contracts pending.
Further reading: Config · Base · Asset · Env · Config Env