vercel/next.js
Debugging
The framework provides a handful of debug surfaces for digging into runtime behavior, build internals, and test failures.
Verbose logs
DEBUG=next:* pnpm next dev # all next: namespaces
DEBUG=next:router pnpm next dev # one namespaceThe debug package (github.com/debug-js/debug) is used throughout the codebase. Common namespaces:
next:*— everythingnext:router— route matching and rewritesnext:font—next/fontresolutionnext:trace— internal tracing
Full stack traces in dev
By default the dev server collapses internal frames into at ignore-listed frames to keep user-facing errors readable. Disable that filter with:
__NEXT_SHOW_IGNORE_LISTED=true pnpm next devImplementation: packages/next/src/server/patch-error-inspect.ts.
Inspecting with the Node debugger
pnpm debug # node --inspect
pnpm debug-brk # node --inspect-brkThese wrap packages/next/dist/bin/next with --inspect[-brk] plus --enable-source-maps and --trace-deprecation. Attach Chrome DevTools at chrome://inspect or your IDE's Node debugger.
Source maps
Two gotchas to know:
findSourceMap()in Node only works when--enable-source-mapsis passed (or returns undefined silently).- Source map paths differ across compilers: webpack writes
./src/..., tsc writessrc/.... Code that consumes them needs to try multiple formats.
Source map handling lives in packages/next/src/server/lib/source-maps.ts and packages/next/src/server/lib/get-source-map-from-file.ts.
Internal process.cwd() differences
process.cwd() produces different paths in tests vs production (test fixtures usually live under a temp directory). Stack-trace formatting that relies on cwd for relative paths needs to be tested in both contexts.
Bundling and module-resolution issues
When something resolves the "wrong" file or pulls in unexpected modules:
- Drop
NEXT_SKIP_ISOLATE=1. Without isolation, tests use the localdist/directly and hide module-resolution bugs that only show up when Next.js is packed as a real npm package. - Inspect the route trace.
.next/traceand thenft.jsonfiles emitted bypackages/next/src/build/collect-build-traces.tstell you which files each route ships. - Webpack stats diff. For webpack-specific regressions, dump stats with
next build --profile(or use@next/bundle-analyzer) and compare before/after.
The runtime-debug agent skill documents this workflow with concrete commands.
Edge runtime quirks
The edge runtime is a sandboxed VM (@edge-runtime/vm) that exposes only Web Standards. Common pitfalls:
- No Node imports —
node:stream,fs,path, etc. are not available. They must be guarded withif (process.env.NEXT_RUNTIME !== 'edge')blocks that webpack DCE can eliminate. react-dom/server.edgediffers from the.nodebuild. Edge has norenderToPipeableStream; onlyrenderToReadableStream. Snapshot tests can diverge between bundlers.define-env.tscontrols user bundle inlining, but the runtime bundle internals (the pre-compiledmodule.compiled.js) are independent. New flags consumed in those internals must also be wired throughnext-server.tsorexport/worker.ts.
The dce-edge agent skill walks through DCE-safe require() patterns for edge.
Telemetry off
By default the framework collects anonymized telemetry. While debugging:
NEXT_TELEMETRY_DISABLED=1 pnpm next devBuild trace inspection
Every next build emits an OpenTelemetry-formatted trace at .next/trace. Convert to a viewable format with the helper scripts:
node scripts/trace-to-tree.mjs .next/trace
node scripts/trace-to-event-format.mjs .next/trace > /tmp/build.json # Chrome trace viewer format
node scripts/clean-trace-jaeger.mjs # ship to JaegerThe pnpm clean-trace-jaeger shortcut runs a clean build with TRACE_TARGET=JAEGER and forwards the trace to a local Jaeger.
Common dev-server crashes
- Stale native binary — if Turbopack throws after a branch switch or pull,
packages/next-swc/native/*.nodemay be stale. Delete it and runpnpm installto fetch the npm-published binary instead of an out-of-date locally-built one. - Cargo incremental ICE — if a Rust build crashes with an internal compiler error, delete
*/incremental/directories under your cargo target dir (defaulttarget/, or whereverCARGO_TARGET_DIRpoints) and retry. - Frozen pnpm lockfile — if install fails after a major dep change, run
pnpm install --no-frozen-lockfile(this is whatpnpm versionscript does internally).
Reproducing test failures
The fastest path to reproducing a single failing CI test:
- Look at the failing job's env in
pr-statusoutput. - Set
IS_WEBPACK_TEST/IS_TURBOPACK_TEST/__NEXT_CACHE_COMPONENTSto match. - Run the single test with
pnpm test-<mode>-<bundler> path/to/test.ts. - Capture output once:
... > /tmp/test-output.log 2>&1. Don't re-run.
If a snapshot disagrees, double-check the env flags before regenerating — env-sensitive snapshots will silently regenerate the wrong baseline if you pass different flags.
Patch-error-inspect
packages/next/src/server/patch-error-inspect.ts patches Node's error inspection to:
- Filter internal frames (toggle with
__NEXT_SHOW_IGNORE_LISTED) - Inject source-map-mapped frames
- Format
Error.causechains
If error stacks look wrong, this file is usually the place to look.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.