Next.jsMedium
What is the Turbopack bundler in Next.js?
Turbopack is the Rust-based, incremental bundler built by Vercel for Next.js. Since Next.js 16 it is stable and the default for both next dev and next build, replacing webpack unless you pass --webpack. It caches work at the function level, including on disk, so rebuilds and restarts stay fast as apps grow.
Key features
- Incremental computation: only work affected by a change is recomputed.
- Filesystem cache: compiler results persist between runs. On by default for
next dev(stable since 16.1) andnext build(16.3), with up to 5.5x faster CI builds reported. - Lazy compilation in dev: only the routes and chunks you request are compiled.
- Unified graph for client, server and edge environments, with fewer inconsistencies.
- Supports CSS Modules, Tailwind/PostCSS, Sass, TypeScript, JSX, many webpack loaders,
import.meta.glob(16.3) and Babel when a config is present.
Configuration
Top-level turbopack in next.config.ts (moved out of experimental in 16):
rules: run webpack loaders for file patterns (for example SVGR for*.svg).resolveAlias,resolveExtensions.rootfor monorepos.
Migrating from webpack
- A custom
webpack()config makesnext buildfail by default in Next.js 16, to avoid silently ignoring it. Port it toturbopackoptions, or runnext build --webpack. - Sass
~imports are not supported; remove the tilde. resolve.fallbackmaps toturbopack.resolveAlias.
Recent additions
Experimental options in 16.3 and 16.4 include memory eviction, a garbage collector (turbopackGc), lazy dynamic imports and a Rust port of the React Compiler (turbopackRustReactCompiler).
Code example
tsx
1// next.config.ts2import type { NextConfig } from "next";34const nextConfig: NextConfig = {5 turbopack: {6 rules: {7 "*.svg": {8 loaders: ["@svgr/webpack"],9 as: "*.js",10 },11 },12 resolveAlias: {13 // Replace a Node module in browser bundles (prefer refactoring instead)14 fs: { browser: "./empty.ts" },15 },16 },17};1819export default nextConfig;2021// package.json22// "dev": "next dev", // Turbopack by default (no --turbopack flag needed)23// "build": "next build", // Turbopack by default24// "build:webpack": "next build --webpack"
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.