Next.js is configured through aDocumentation 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.config.js (or next.config.ts) file at the root of your project.
next.config.js basics
next.config.js
.js file, or use next.config.ts for full TypeScript support:
next.config.ts
Environment variables
Built-in .env support
Next.js loads environment variables from .env files automatically:
| File | Scope |
|---|---|
.env | All environments |
.env.local | Local overrides (gitignored) |
.env.development | next dev only |
.env.production | next build / next start only |
.env.test | Test environment only |
.env.local
pages/api/data.ts
Exposing variables to the browser
Variables prefixed withNEXT_PUBLIC_ are included in the client-side bundle:
.env.local
pages/index.tsx
Runtime environment variables
For values that differ between deployments (not build time), access them ingetServerSideProps or API routes at runtime:
TypeScript
Next.js has zero-configuration TypeScript support. Create or leave atsconfig.json at the root and run next dev—Next.js configures it automatically.
Strict mode
Enable strict type checking:tsconfig.json
Pages Router TypeScript types
Key types from thenext package:
ESLint
Next.js includes a built-in ESLint configuration. Run it with:create-next-app sets this up automatically. For manual setup:
.eslintrc.json
next/core-web-vitals preset is stricter than next and enables rules that affect Core Web Vitals.
Absolute imports
Configure thebaseUrl in tsconfig.json (or jsconfig.json for JavaScript projects) to use absolute imports:
tsconfig.json
Module aliases
For custom path aliases:tsconfig.json
Headers, redirects, and rewrites
Configure HTTP headers, redirects, and URL rewrites innext.config.js:
next.config.js
Customizing the build directory
The default build output directory is.next. You can change it:
next.config.js
Page extensions
By default, Next.js looks for.js, .jsx, .ts, and .tsx files in pages/. You can customize this:
next.config.js
pages/index.page.tsx maps to / and plain .tsx files in pages/ are ignored (useful for co-locating tests with pages).