
Next.js Bundle Analyzer With Turbopack: What It Catches
If your Next.js app builds with Turbopack, @next/bundle-analyzerwon't give you a report. The tool that does is built in: next analyze on 16.4 and later, next experimental-analyze on 16.1 to 16.3. I ran both on Next.js 16.4.6 and 16.2.10 this morning, against a small fixture and against this site. The most useful thing the new analyzer found wasn't a big dependency. It was one innocent constant import that put 307 KB of gzipped "lazy" code into the first load.
Why Does @next/bundle-analyzer Show Nothing on Next.js 16?
Because Turbopack has been the default bundler since Next.js 16, and @next/bundle-analyzer is a Webpack plugin. I wired it up the usual way (withBundleAnalyzer in next.config.js, then ANALYZE=true next build) on 16.4.6. The build succeeded and printed this:
The Next Bundle Analyzer is not compatible with Turbopack builds, no report will be generated.
Consider trying the new Turbopack analyzer via `next analyze`.
To run this analysis pass the `--webpack` flag to `next build`.next/analyze didn't exist afterwards. With next build --webpack the old plugin still works: it wrote client.html, nodejs.html and edge.html in 6.9 seconds. But a Webpack report describes a build you don't ship. Turbopack chunks differently, so if production builds with Turbopack, analyze Turbopack.
Which Command Works on Which Next.js Version?
This is where most of the confusion comes from. The current docs say next analyze, but that name arrived in 16.4. On 16.2.10, which is what a lot of projects are still pinned to (this site included), the CLI doesn't know the word and treats it as a folder:
$ npx next analyze # Next.js 16.2.10
Invalid project directory provided, no such directory: /.../v162/analyzenext experimental-analyze worked fine on 16.2.10, and 16.4.6 accepts both names (its help text lists analyze|experimental-analyze). The export subcommand is 16.4 only. On 16.2 it fails the same way, looking for a directory called export.
# Next.js 16.4+
npx next analyze # web UI on :4000
npx next analyze --output --snapshot before
npx next analyze export --snapshot before --route /b > before.jsonl
# Next.js 16.1 - 16.3 (analyze and export don't exist yet)
npx next experimental-analyze --outputIt doesn't build your app. The analyzer compiles a production graph and stops. On the fixture it took 2.4 seconds. On this site (170 routes) it took 5.6 seconds and produced a 51 MB JSON Lines export.
Why Is My Lazy-Loaded Component Still in the First Load?
Vercel's post on the bundle optimizer skill makes one claim I wanted to check: React.lazy only defers a module if nothing else in the bundle imports it statically. So I built a fixture with five routes. Each one renders a code block with the full highlight.jsbuild behind a "show" button. Then I loaded every route in headless Chromium, recorded each JavaScript response before and after the click, and gzipped them to compare.
| Route | Setup | Initial JS (gzip) | Loaded on click |
|---|---|---|---|
| /e | highlight.js used only in a Server Component | 135.0 KB (5 files) | n/a |
| /a | React.lazy, nothing else imports the file | 135.3 KB (6 files) | +307.0 KB |
| /b | React.lazy + a badge imports one constant from the same file | 442.2 KB (7 files) | 0 KB |
| /c | Same as /b, constant moved to its own file | 135.4 KB (6 files) | +307.0 KB |
| /d | next/dynamic (ssr: false) + the same badge import | 443.7 KB (7 files) | 0.1 KB |
Route /b is the trap. The loader is written correctly. The problem is a second client component that needs a list of language names, and that list happens to live in the heavy file:
// BadgeB.tsx: looks harmless
'use client';
import { LANGS_B } from './HeavyB'; // one tiny array...
// LoaderB.tsx: looks lazy
const HeavyB = lazy(() => import('./HeavyB')); // ...but this is now eagerThat one import made the route 3.3x heavier: 442 KB of gzipped JavaScript instead of 135 KB, and the click loaded nothing because it was all there already. No warning, no build error, and the page works perfectly. You only notice it in Lighthouse or on a slow phone.
next/dynamic with ssr: false doesn't save you either. Route /d came out at 444 KB. The fix in /c is boring: move the constant to langs.ts, and the route drops back to 135 KB with the 307 KB arriving on click. Types, constants, zod schemas and helper functions that sit next to a heavy component are the usual culprits.
How Do You Find the Import With next analyze export?
The web UI on port 4000 is good for browsing. For a question like "why is this module in the initial load", the JSON export is faster. Each line is a record: meta, route, module (with sync, async and traced dependency lists), output, part(one module's slice of a chunk, with size and compressed_size) and group. Groups carry a kind: bootstrap, render_dependent or async. Anything not in an async group loads up front.
This script answers both questions for one route:
import json, sys
from collections import defaultdict
path, route = sys.argv[1], sys.argv[2]
needle = sys.argv[3] if len(sys.argv) > 3 else None
recs = [json.loads(line) for line in open(path)]
parts = defaultdict(list)
for r in recs:
if r["type"] == "part" and r["route"] == route:
parts[r["filename"]].append(r)
initial, deferred = set(), set()
for g in recs:
if g["type"] != "group" or g["route"] != route:
continue
for f in g["outputs"]:
if f.startswith("[client-fs]") and f.endswith(".js"):
(deferred if g["kind"] == "async" else initial).add(f)
deferred -= initial
def kb(files):
return sum(p["compressed_size"] for f in files for p in parts[f]) / 1000
print(f"initial: {len(initial)} files, {kb(initial):.1f} KB compressed")
print(f"deferred: {len(deferred)} files, {kb(deferred):.1f} KB compressed")
if needle: # who imports this module synchronously on the client?
for r in recs:
if r["type"] != "module":
continue
for dep in r["dependencies"]["sync"]:
if needle in dep and "[app-client]" in dep:
print("static import:", r["path"], "->", needle)I ran it against a snapshot taken before the fix and one taken after, both exported with --route /b:
$ python3 route_js.py before.jsonl /b HeavyB
initial: 7 files, 522.8 KB compressed
deferred: 0 files, 0.0 KB compressed
static import: [project]/components/BadgeB.tsx -> HeavyB
$ python3 route_js.py after.jsonl /b HeavyB
initial: 6 files, 171.8 KB compressed
deferred: 2 files, 351.0 KB compressedIt names the exact file, which is what you need. One caveat: compressed_sizeis the analyzer's per-module estimate, and it ran about 14% above what the browser actually saw (351 KB estimated for highlight.js vs 307 KB when I gzipped the real chunks). Use it to compare snapshots, not to quote absolute sizes. The file counts matched the browser on every route.
What about the next-bundle-optimizer skill?
Vercel ships an agent skill (npx skills add vercel/next.js --skill next-bundle-optimizer) that reads these same snapshots and proposes import boundaries. I didn't run it for this post, so I can't vouch for its suggestions. The export is useful on its own, though, and having the raw graph is how you check what an agent tells you. If your agent ignores installed skills, I wrote up why Claude skips skills and how to fix it.
Can You Enforce a Bundle Budget in CI Without the Analyzer?
Yes, and this was the find I didn't expect. A plain next build writes .next/diagnostics/route-bundle-stats.json: one entry per route with firstLoadUncompressedJsBytes and the list of first-load chunks. Its numbers matched the uncompressed bytes Chromium downloaded on all five fixture routes, to the byte (1,425,432 for /b, 457,622 for /a). It isn't new, either: this site's 16.2.10 build writes it too, and its heaviest route, /testimonials, comes in at 603,488 bytes. That makes a budget check a dozen lines:
// scripts/check-bundle-budget.mjs (run after next build)
import { readFileSync } from "node:fs";
const BUDGET = 650_000; // uncompressed bytes of first-load JS per route
const stats = JSON.parse(readFileSync(".next/diagnostics/route-bundle-stats.json", "utf8"));
const over = stats.filter((r) => r.firstLoadUncompressedJsBytes > BUDGET);
for (const r of over) console.error(`${r.route}: ${r.firstLoadUncompressedJsBytes} bytes`);
process.exit(over.length ? 1 : 0);Uncompressed bytes are the right unit for a budget anyway, since parse and execute cost on a phone scales with them, not with gzip size. If you deploy on Vercel, run it before the deploy step so a regression never reaches production. My notes on which Vercel deploy paths skip the build matter here: a prebuilt deploy only gets checked if your pipeline checks it.
What Did It Find on a Real Site?
I copied this site's repo to a scratch folder, swapped in Next.js 16.4.6 and ran the analyzer. The site is mostly Server Components, so I expected a short report, and that's what I got. All 158 blog posts ship the same first-load JavaScript, about 193 KB by the analyzer's estimate, and roughly 180 KB of that is Next.js and React. The site's own components add about 2 KB on a blog post.
The one real finding was the testimonials page.It's the heaviest route at 204 KB, because a client component imports lib/testimonials-data.ts: 45 KB of quotes, 13 KB compressed, shipped as JavaScript. And I'll probably leave it. That page has live search and filtering over every testimonial, so the data has to reach the browser somehow, and passing it as props from a Server Component would just move the same bytes into the RSC payload.
That's the part the tooling can't decide for you. The analyzer shows where the bytes come from. Whether they're worth it depends on what the page does, which is the same judgment call I hit with 'use cache: private' that quietly didn't cache. The framework does exactly what the code says, and the code says something you didn't mean.
The Short Version
- Turbopack build? Drop
@next/bundle-analyzer. Usenext analyze(16.4+) ornext experimental-analyze(16.1 to 16.3). - "Invalid project directory" from
next analyzemeans you're below 16.4. - Lazy isn't lazy if any client file imports the same module statically, even for one constant. That applies to
React.lazyandnext/dynamic. - Save snapshots with
--snapshotand diff them withnext analyze export, or let the Turbopack graph tell you who imports what. - For CI, read
route-bundle-stats.jsonafternext build. No analyzer needed.
How I Tested This
November 29, 2026, on a Mac mini in Allen, TX. Two scratch projects with React 19 and highlight.js 11: one on next@16.4.6 (current latest) and one on next@16.2.10, each with the five-route fixture above. Sizes in the table come from next start plus Playwright Chromium: every .jsresponse body captured before and after clicking the button, gzipped with Node's default level. Analyzer numbers come from next analyze export. The real-site run used a copy of this repo with only the Next.js version changed. It wasn't deployed. One fixture and one fairly lean site, so treat the ratios as an illustration of the mechanism, not a benchmark.
Is Your Next.js App Heavier Than It Should Be?
I build and tune production Next.js apps on Vercel, from AI dashboards to marketing sites. If your Lighthouse score dropped after a feature or a Next.js 16 upgrade and you can't tell why, send me the repo and the route.
Related Posts
Full-Stack
Supabase Legacy API Keys Deprecated: How to Migrate
Supabase retires the legacy anon and service_role keys by the end of 2026. Tested on a live project: Bearer-only calls fail for old and new keys alike, supabase-js works unchanged, verify_jwt accepts any valid project key, and a bare Mozilla/5.0 user agent blocks the secret key.
Full-Stack
Vercel Node.js 20.x Discontinued Error: How to Fix It
Since October 1, 2026 Vercel refuses new builds on Node.js 20. Tested on a throwaway project: engines 20.x, ^20.11.0 and >=18 <21 fail in under a second, >=20 quietly runs Node 24, engines overrides Project Settings, .nvmrc is ignored, and the API still accepts 20.x.
Full-Stack
Vercel Workflow DevKit: Durable AI Agents Guide
Every tool call an agent makes becomes a persisted, retryable step, so a crash, a redeploy, or a pause that lasts weeks resumes exactly where it left off instead of starting over. How DurableAgent, "use step", and createHook actually work — and where n8n still wins.