Key packages
next
The main framework package published to npm. Contains the dev server, build pipeline, routing, and all runtime code for client and server.
create-next-app
The project scaffolding CLI. Bootstraps a new Next.js application with sensible defaults and optional templates.
@next/swc
Native Rust bindings for the SWC compiler. Handles TypeScript and JSX transpilation, minification, and code transforms — replacing Babel.
Turbopack
A Rust-based incremental bundler integrated into
next dev and next build. Uses demand-driven evaluation and persistent caching for fast rebuild times.Repository structure
The Next.js repository is a pnpm monorepo:Compilation pipeline
When you runnext build, Next.js orchestrates several compilation stages:
Configuration loading
Next.js reads
next.config.js (or next.config.ts), resolves jsconfig.json / tsconfig.json, and constructs the full build configuration including compiler options, environment variables, and feature flags.Entry point discovery
The framework walks your
app/ or pages/ directory to collect all routes, layouts, and special files (loading.tsx, error.tsx, not-found.tsx). These become Webpack or Turbopack entry points.Bundling
Turbopack (default) or Webpack compiles and bundles each entry point. The SWC compiler handles TypeScript and JSX transforms. Tree-shaking, code splitting, and chunk optimization happen here.
Rendering
Static pages are pre-rendered at build time. Server components are analyzed to separate server-only code from client bundles. Dynamic routes emit server functions instead of static HTML.
Rendering strategies
Next.js supports multiple rendering strategies that can be mixed within a single application:- Static (SSG)
- Server (SSR)
- Client (CSR)
- Streaming
Pages are rendered at build time and served as static HTML. No server required at request time. Ideal for content that doesn’t change per user.
Client and server boundary
Next.js uses the React Server Components model to split your application into two execution environments:- Server components run only on the server (or at build time). They can access databases, file systems, and secrets directly. They never ship JavaScript to the browser.
- Client components are prefixed with
'use client'. They hydrate in the browser and can use stateful hooks and browser APIs.
Build output
After a successful build, the.next/ directory contains:
| Path | Contents |
|---|---|
.next/server/ | Server-side bundles and HTML for pre-rendered pages |
.next/static/ | Hashed client-side JS chunks, CSS, and media |
.next/cache/ | Incremental build cache (Turbopack persistent cache) |
.next/BUILD_ID | Unique identifier for the current build |
.next/routes-manifest.json | Route metadata used by the server at runtime |
The development branch is
canary. All pull requests should be opened against canary, not main.