Turbopack is a Rust-based incremental bundler built into Next.js that dramatically speeds up development server startup and hot-module replacement compared to the default Webpack bundler. Nextra fully supports Turbopack in development mode and automatically configures the necessary loaders and aliases so your MDX content, page maps, and theme all work without any manual setup.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/shuding/nextra/llms.txt
Use this file to discover all available pages before exploring further.
Enabling Turbopack
To enable Turbopack for your development server, add the--turbopack flag to your next dev command:
package.json
Without the
--turbopack flag, Next.js uses Webpack
under the hood — a JavaScript-based bundler. Turbopack is the Rust-based replacement and
is only used during development; next build always uses Webpack for production builds
(for now).What Nextra Configures Automatically
When Turbopack is detected, Nextra automatically applies several configuration changes inside itswithNextra() plugin so you do not have to configure them manually.
Automatic transpilePackages
When Turbopack is active (Next.js sets TURBOPACK=1 in Next.js 15 or TURBOPACK=auto in Next.js 16+), Nextra adds ESM-only packages to transpilePackages to prevent module resolution errors:
Turbopack loaders for MDX
Nextra registers custom Turbopack loaders that handle.md and .mdx file transformation. These are equivalent to the Webpack loaders Nextra registers when Turbopack is not used:
| Pattern | Loader purpose |
|---|---|
./{src/,}app/**/page.{md,mdx} | Page-level MDX imports (full page transform) |
*.{md,mdx} | Partial/component MDX imports |
**/nextra/dist/server/page-map/placeholder.js | Page map placeholder |
**/nextra/dist/server/page-map/get.js | Page map data fetcher |
resolveAlias entries
Nextra also adds Turbopack resolveAlias entries to fix module resolution for MDX and optional packages:
Version-based Configuration Key
Turbopack configuration lives under different keys depending on the Next.js version. Nextra handles this automatically:- Next.js 16+ (≥ 15.3)
- Next.js ≤ 15.2
Nextra uses the top-level
turbopack key in the Next.js config object:next.config.mjs
next package version at build time:
Serializable Options Only
Turbopack requires that all loader options be JSON-serializable. This means you cannot pass function-based plugin options — such asremarkPlugins, rehypePlugins, or recmaPlugins — when running next dev --turbopack.
The following configuration works only with Webpack (i.e., next build or next dev without --turbopack):
next.config.mjs
Workaround: apply plugins in mdx-components.tsx
For plugins that transform MDX output, consider applying transformations at the component level in your mdx-components.tsx file, or use the next build path (which uses Webpack) for plugin-dependent builds.
Because
next build does not yet support Turbopack, all production builds use Webpack and
therefore do support function-based plugin options. The serialization constraint applies
only to next dev --turbopack.Summary
What Nextra does automatically with Turbopack
What Nextra does automatically with Turbopack
- Registers
.mdand.mdxTurbopack loaders - Sets up
resolveAliasfor MDX and Mermaid modules - Adds
shikiandts-morphtotranspilePackageswhenTURBOPACK=1(Next.js 15) orTURBOPACK=auto(Next.js 16+) is set - Uses
turbopackkey (Next.js 16+) orexperimental.turbokey (Next.js ≤ 15.2) automatically
What you still need to do
What you still need to do
- Add
--turbopackto yournext devscript inpackage.json - Avoid passing function-based remark/rehype/recma plugins in
nextra()options when usingnext dev --turbopack
Turbopack vs Webpack availability
Turbopack vs Webpack availability
| Command | Bundler |
|---|---|
next dev | Webpack |
next dev --turbopack | Turbopack |
next build | Webpack (always) |
next start | N/A (serves pre-built output) |