turbopack
Turbopack expert guidance. Use when configuring the Next.js bundler, optimizing HMR, debugging build issues, or understanding the Turbopack vs Webpack differences.
- License 许可
- MIT
- 最近更新
- 2026-11-12
- Stars
- ★ 1
- Forks
- 1
01 前言 Front Matter
- name
- turbopack
- chainTo
- [ { "message": "Webpack config detected — loading Next.js guidance for migrating webpack customizations to Turbopack top-level config in Next.js 16.", "pattern": "webpack\\s*:\\s*\\(|webpack\\s*\\(config", "targetSkill": "nextjs" }, { "message": "Turbopack configuration detected — loading Next.js guidance for top-level turbopack config syntax in Next.js 16 (moved from experimental.turbopack).", "pattern": "turbopack\\s*:\\s*\\{|experimental\\.turbopack", "targetSkill": "nextjs" } ]
- metadata
- { "docs": [ "https://turbo.build/pack/docs", "https://nextjs.org/docs/architecture/turbopack" ], "sitemap": "https://turbo.build/sitemap.xml", "priority": 4, "bashPatterns": [ "\\bnext\\s+dev\\s+--turbo\\b", "\\bnext\\s+dev\\s+--turbopack\\b" ], "pathPatterns": [ "next.config.*" ] }
- retrieval
- { "aliases": [ "next bundler", "turbopack", "fast bundler", "hmr" ], "intents": [ "enable turbopack", "fix build issue", "speed up dev server", "configure bundler" ], "entities": [ "Turbopack", "HMR", "bundler", "next dev --turbopack" ] }
- description
- Turbopack expert guidance. Use when configuring the Next.js bundler, optimizing HMR, debugging build issues, or understanding the Turbopack vs Webpack differences.
03 SKILL.md 正文
Turbopack
You are an expert in Turbopack — the Rust-powered JavaScript/TypeScript bundler built by Vercel. It is the default bundler in Next.js 16.
Key Features
- Instant HMR: Hot Module Replacement that doesn't degrade with app size
- File System Caching (Stable): Dev server artifacts cached on disk between restarts — up to 14x faster startup on large projects. Enabled by default in Next.js 16.1+, no config needed. Build caching planned next.
- Multi-environment builds: Browser, Server, Edge, SSR, React Server Components
- Native RSC support: Built for React Server Components from the ground up
- TypeScript, JSX, CSS, CSS Modules, WebAssembly: Out of the box
- Rust-powered: Incremental computation engine for maximum performance
Configuration (Next.js 16)
In Next.js 16, Turbopack config is top-level (moved from experimental.turbopack):
// next.config.ts
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
turbopack: {
// Resolve aliases (like webpack resolve.alias)
resolveAlias: {
'old-package': 'new-package',
},
// Custom file extensions to resolve
resolveExtensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
},
}
export default nextConfig
CSS and CSS Modules Handling
Turbopack handles CSS natively without additional configuration.
Global CSS
Import global CSS in your root layout:
// app/layout.tsx
import './globals.css'
CSS Modules
CSS Modules work out of the box with .module.css files:
// components/Button.tsx
import styles from './Button.module.css'
export function Button({ children }) {
return <button className={styles.primary}>{children}</button>
}
PostCSS
Turbopack reads your postcss.config.js automatically. Tailwind CSS v4 works with zero config:
// postcss.config.js
module.exports = {
plugins: {
'@tailwindcss/postcss': {},
autoprefixer: {},
},
}
Sass / SCSS
Install sass and import .scss files directly — Turbopack compiles them natively:
npm install sass
import styles from './Component.module.scss'
Common CSS pitfalls
- CSS ordering differs from webpack: Turbopack may load CSS chunks in a different order. Avoid relying on source-order specificity across files — use more specific selectors or CSS Modules.
@importin global CSS: Use standard CSS@import— Turbopack resolves them, but circular imports cause build failures.- CSS-in-JS libraries:
styled-componentsandemotionwork but require their SWC plugins configured undercompilerin next.config.
Tree Shaking
Turbopack performs tree shaking at the module level in production builds. Key behaviors:
- ES module exports: Only used exports are included — write
exporton each function/constant rather than barrelexport * - Side-effect-free packages: Mark packages as side-effect-free in
package.jsonto enable aggressive tree shaking:
{
"name": "my-ui-lib",
"sideEffects": false
}
- Barrel file optimization: Turbopack can skip unused re-exports from barrel files (
index.ts) when the package declares"sideEffects": false - Dynamic imports:
import()expressions create async chunk boundaries — Turbopack splits these into separate chunks automatically
Diagnosing large bundles
Built-in analyzer (Next.js 16.1+, experimental): Works natively with Turbopack. Offers route-specific filtering, import tracing, and RSC boundary analysis:
// next.config.ts
const nextConfig: NextConfig = {
experimental: {
bundleAnalyzer: true,
},
}
Legacy @next/bundle-analyzer: Still works as a fallback:
ANALYZE=true next build
// next.config.ts
import withBundleAnalyzer from '@next/bundle-analyzer'
const nextConfig = withBundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
})({
// your config
})
Custom Loader Migration from Webpack
Turbopack does not support webpack loaders directly. Here is how to migrate common patterns:
| Webpack Loader | Turbopack Equivalent |
|---|---|
css-loader + style-loader |
Built-in CSS support — remove loaders |
sass-loader |
Built-in — install sass package |
postcss-loader |
Built-in — reads postcss.config.js |
file-loader / url-loader |
Built-in static asset handling |
svgr / @svgr/webpack |
Use @svgr/webpack via turbopack.rules |
raw-loader |
Use import x from './file?raw' |
graphql-tag/loader |
Use a build-time codegen step instead |
worker-loader |
Use native new Worker(new URL(...)) syntax |
Configuring custom rules (loader replacement)
For loaders that have no built-in equivalent, use turbopack.rules:
// next.config.ts
const nextConfig: NextConfig = {
turbopack: {
rules: {
'*.svg': {
loaders: ['@svgr/webpack'],
as: '*.js',
},
},
},
}
When migration isn't possible
If a webpack loader has no Turbopack equivalent and no workaround, fall back to webpack:
const nextConfig: NextConfig = {
bundler: 'webpack',
}
File an issue at github.com/vercel/next.js — the Turbopack team tracks loader parity requests.
Production Build Diagnostics
Build failing with Turbopack
- Check for unsupported config: Remove any
webpack()function from next.config — it's ignored by Turbopack and may mask the real config - Verify
turbopack.rules: Ensure custom rules reference valid loaders that are installed - Check for Node.js built-in usage in edge/client: Turbopack enforces environment boundaries —
fs,path, etc. cannot be imported in client or edge bundles - Module not found errors: Ensure
turbopack.resolveAliascovers any custom resolution that was previously in webpack config
Build output too large
- Audit
"use client"directives — each client component boundary creates a new chunk - Check for accidentally bundled server-only packages in client components
- Use
server-onlypackage to enforce server/client boundaries at import time:
npm install server-only
// lib/db.ts
import 'server-only' // Build fails if imported in a client component
Comparing webpack vs Turbopack output
Run both bundlers and compare:
# Turbopack build (default in Next.js 16)
next build
# Webpack build
BUNDLER=webpack next build
Compare .next/ output sizes and page-level chunks.
Performance Profiling
HMR profiling
Enable verbose HMR timing in development:
NEXT_TURBOPACK_TRACING=1 next dev
This writes a trace.json to the project root — open it in chrome://tracing or Perfetto to see module-level timing.
Build profiling
Profile production builds:
NEXT_TURBOPACK_TRACING=1 next build
Look for:
- Long-running transforms: Indicates a slow SWC plugin or heavy PostCSS config
- Large module graphs: Reduce barrel file re-exports
- Cache misses: If incremental builds aren't hitting cache, check for files that change every build (e.g., generated timestamps)
Memory usage
Turbopack's Rust core manages its own memory. If builds OOM:
- Increase Node.js heap:
NODE_OPTIONS='--max-old-space-size=8192' next build - Reduce concurrent tasks if running inside Turborepo:
turbo build --concurrency=2
Turbopack vs Webpack
| Feature | Turbopack | Webpack |
|---|---|---|
| Language | Rust | JavaScript |
| HMR speed | Constant (O(1)) | Degrades with app size |
| RSC support | Native | Plugin-based |
| Cold start | Fast | Slower |
| Ecosystem | Growing | Massive (loaders, plugins) |
| Status in Next.js 16 | Default | Still supported |
| Tree shaking | Module-level | Module-level |
| CSS handling | Built-in | Requires loaders |
| Production builds | Supported | Supported |
When You Might Need Webpack
- Custom webpack loaders with no Turbopack equivalent
- Complex webpack plugin configurations (e.g.,
ModuleFederationPlugin) - Specific webpack features not yet in Turbopack (e.g., custom
externalsfunctions)
To use webpack instead:
// next.config.ts
const nextConfig: NextConfig = {
bundler: 'webpack', // Opt out of Turbopack
}
Development vs Production
- Development: Turbopack provides instant HMR and fast refresh
- Production: Turbopack handles the production build (replaces webpack in Next.js 16)
Common Issues
- Missing loader equivalent: Some webpack loaders don't have Turbopack equivalents yet. Check Turbopack docs for supported transformations.
- Config migration: Move
experimental.turbopackto top-levelturbopackin next.config. - Custom aliases: Use
turbopack.resolveAliasinstead ofwebpack.resolve.alias. - CSS ordering changes: Test visual regressions when migrating — CSS chunk order may differ.
- Environment boundary errors: Server-only modules imported in client components fail at build time — use
server-onlypackage.
Official Documentation
04 同仓库更多 Skills
grilling
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
social
When the user wants help creating, scheduling, or optimizing social media content for LinkedIn, Twitter/X, Instagram, TikTok, Facebook, or other platforms, or wants to do social listening and engagement triage. Also use when the user mentions 'LinkedIn post,' 'Twitter thread,' 'social media,' 'content calendar,' 'social scheduling,' 'engagement,' 'viral content,' 'what should I post,' 'repurpose this content,' 'tweet ideas,' 'LinkedIn carousel,' 'social media strategy,' 'grow my following,' 'TikTok video,' 'Reels,' 'Shorts,' 'video script,' 'video hook,' 'short-form video,' 'create a reel,' 'social listening,' 'brand mentions,' 'competitor monitoring,' 'top posts to comment on,' 'find people asking for,' 'carousel,' 'slide-by-slide,' or 'document post.' Use this for social media content creation, repurposing, scheduling, short-form video scripting, and social listening. For broader content strategy, see content-strategy. For paid ads, see ad-creative. For earned media, see public-relations.
code-review
Review the changes since a fixed point (commit, branch, tag, or merge-base) along five axes: Standards (does the code follow this repo's documented coding standards?), Spec (does the code match what the originating issue/spec asked for?), Evidence (does each claim in the pull request have evidence that shows it?), Bugs (does the changed code have logic errors, unhandled states, races, or regressions?), and Security (does the change open injection, auth, secret, input, or CI workflow holes?). Runs the reviews in parallel sub-agents, tags every finding Important, Nit, or Pre-existing, and reports them side by side with what blocks merge. Given an earlier reviewed head and its findings, it reviews only the newer commits, rechecks the earlier findings, and never repeats one. Use when the user wants to review a branch, a PR, work-in-progress changes, or asks to "review since X".
writing-for-pstack
Write or tighten an operator prompt for a patina-mode run. Use when the operator asks to write, revise, or review a prompt that will be passed to patina-mode.
writing-for-agents
Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.
wizard
Generate an interactive bash wizard that walks a human through steps only they can perform. Use when provisioning infrastructure, setting up credentials or CI secrets, walking an unfamiliar third-party dashboard, or running a one-off migration or cutover. Don't invoke this for steps the agent can perform itself.