Turbopack and the dev server

Beginner · 6 min

What a bundler does, why Next.js 16 made Turbopack the default for dev and build, how it works, and when you might still pass the --webpack flag.

Before thisCreating a Next.js project

Tobi Mey · 6 min

Turbopack and the dev server

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Tobi MeyReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A bundler turns your many source modules, TypeScript and CSS into the files a browser can load, and in development it has to redo that work after every edit.
  • Turbopack is Next.js's Rust-based incremental bundler; in Next.js 16 it is the default for both `next dev` and `next build`, and `--webpack` opts back into webpack.
  • Turbopack is fast for three reasons the docs name: one unified graph for client and server code, caching results down to the function level, and bundling only what the dev server is asked for.
  • Turbopack does not type-check. Your editor and `next build` do.

What a bundler is for

Your project is hundreds of small files: TSX components, CSS, images, JSON, packages from node_modules. A browser cannot load that tree as-is, and it should not try; hundreds of separate requests would be slow. So a bundler reads your entry points, follows every import, compiles each file (TypeScript to JavaScript, JSX to function calls, Tailwind and CSS modules to plain CSS), and writes out a few optimized files.

In Next.js the job is bigger than for a single-page app. The same source tree produces code for several environments: the server that renders Server Components, the server that renders HTML for Client Components, and the browser. All three have to agree about which module is which, which is where "use client" boundaries come in later.

The development problem

In production you pay the bundling cost once, at build time. In development you pay it constantly. Every time you save, something has to recompile, and you want the browser to update before you have switched windows. That is the problem Turbopack was written for.

What Turbopack does

Turbopack is an incremental bundler, written in Rust, built into Next.js. The docs give four reasons for its design:

  • One unified graph. Instead of running separate compilers for client and server and stitching the outputs together, it models every environment in one graph.
  • Bundling in dev, but lazily. Some tools skip bundling in development and let the browser load native ES modules. That works for small apps and gets slow for large ones with thousands of requests. Turbopack bundles, but only what the dev server is actually asked for. Open one route and only that route’s modules compile.
  • Incremental computation. It caches results down to the function level, so after your first run an edit recomputes only what depends on it. The cache persists to disk between runs.
  • Native speed. It parallelizes across cores.

As of Next.js 16, none of this needs configuration. Running next dev or next build uses Turbopack. If a plugin or loader you depend on only works with webpack, run next dev --webpack or next build --webpack. That flag is an escape hatch, not the recommended path.

What it does not do

Turbopack compiles TypeScript but does not check types. When I ran next build on a scratch app, the output showed a separate “Running TypeScript” step after compilation; that step, plus your editor, is what catches type errors. It supports Fast Refresh, Server Components, CSS Modules, Sass, PostCSS and global CSS out of the box. Some webpack-era features are unsupported or limited; for example, custom Sass functions are not supported. If your project has a Babel config file, Next.js 16 picks it up automatically for that case.

Configuration lives under the turbopack key in next.config.ts. The scaffold uses it to register a loader for Tailwind’s CSS handling.

A mental model for the dev server

Think of next dev as a restaurant that cooks to order rather than prepping everything at opening. Request a route and the server compiles what that route needs, renders it, and caches the work. Request it again and most of the work is already done. That is why a huge project starts quickly and the first visit to a new route feels slower than the second.

What the video covers

Tobi Mey’s video has four chapters: what bundling is, webpack versus Turbopack, how to use Turbopack, and its problems. It matches this lesson’s framing well. One caution on age: it was published in February 2025, when Turbopack was an opt-in flag for next dev. In Next.js 16 it is the default for dev and build, and the “problems” chapter reflects the earlier state, so treat the flag instructions as historical and the explanation of bundling as current. For the 16-era view, ByteGrad’s Next.js 16 video has a Turbopack chapter.

Where this fits

You now know what runs when you start the dev server. The next group, routing, begins with the file-system router.

Check yourself

  1. 01What problem does a bundler solve for a Next.js app?

    Browsers cannot load hundreds of TypeScript, JSX and CSS modules directly. The bundler compiles them, resolves imports, splits code into chunks and produces the assets the browser and the server actually run.

  2. 02Why is incremental computation important in development?

    You change one file and expect the page to update in an instant. If the bundler redid all its work each time, large apps would crawl. By caching results per function, it only recomputes what depends on the edit.

  3. 03Does Turbopack catch TypeScript errors in `next dev`?

    No. It compiles TypeScript but does not check types. Type errors show up in your editor and when `next build` runs the TypeScript pass.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark