Slow dev startup in Next.js almost always comes down to one of three things: module count, heavy config work at boot, or something outside the compiler entirely. Here's how to narrow it down fast.
1. Get a baseline
Start the server with profiling on and note the two numbers it prints:
NEXT_TURBOPACK_TRACING=1 next dev
- Startup time: everything before "Ready". Config loading, env files, plugins.
- First compile: the time after you hit a route. Module graph size lives here.
2. Check the usual suspects
| Symptom | Likely cause |
|---|---|
| Slow before "Ready" | Heavy next.config, sync I/O in config, large .env cascade |
| Slow first page | Barrel files pulling in whole icon or UI libraries |
| Slow every save | Type checking or lint running in the dev loop |
The barrel-file one is the classic. A single import { Check } from "lucide-react" through a barrel can pull thousands of modules into the graph. Fix it with:
// next.config.ts
const nextConfig = {
experimental: {
optimizePackageImports: ["lucide-react", "@acme/ui"],
},
}
3. Measure, don't guess
If neither jumps out, generate a trace and look at the actual spans:
next dev
# reproduce the slow start, then:
next internal trace .next/trace
Compare against a bare
create-next-appon the same machine first. If that's also slow, the problem is your machine or antivirus scanningnode_modules, not your app.
Want to paste the first few lines of your trace output? I can point at the exact span that's eating the time.