Next.jsMedium

How do you debug a Next.js application?

Debug server code with next dev --inspect (Next.js 16.1+) and Chrome DevTools or VS Code breakpoints, and client code with browser DevTools and React DevTools. Use the Next.js error overlay and DevTools panel, terminal logs (including Server Function logs since 16.2), next build --debug-prerender for build errors, and the MCP endpoint for AI coding agents.

Server-side

  • next dev --inspect attaches the Node.js inspector to the process that runs your code (replacing the old NODE_OPTIONS=--inspect workaround). Open chrome://inspect or attach from VS Code.
  • next start --inspect (16.2) debugs a production server.
  • VS Code launch configs for server-side, client-side and full-stack debugging (documented in the Next.js debugging guide).
  • Logs: console.log in Server Components prints in the terminal; in dev Next.js also forwards server logs to the browser console. Server Function calls are logged with name, arguments, duration and file.
  • logging.fetches.fullUrl: true in next.config logs every fetch with cache hits and misses.

Client-side

  • Browser DevTools: Sources breakpoints, Network (filter _rsc for RSC requests), Performance.
  • React DevTools: component tree, props, Profiler, Suspense and error boundary toggles.

Next.js tooling

  • Error overlay with source-mapped stacks, hydration diffs and Error.cause chains.
  • Next.js DevTools (the indicator button): route info, Cache Components insights, Navigation Inspector to pause at the loading state.
  • next build --debug-prerender for readable prerender errors; --debug-build-paths to build a subset.
  • next info for bug reports.
  • MCP: the dev server exposes /_next/mcp so coding agents can read errors, routes and logs.

Code example

tsx
1// .vscode/launch.json
2// {
3// "version": "0.2.0",
4// "configurations": [
5// {
6// "name": "Next.js: debug server",
7// "type": "node-terminal",
8// "request": "launch",
9// "command": "npx next dev --inspect"
10// },
11// {
12// "name": "Next.js: debug client",
13// "type": "chrome",
14// "request": "launch",
15// "url": "http://localhost:3000"
16// }
17// ]
18// }
19
20// next.config.ts - see fetch cache behavior in the terminal
21import type { NextConfig } from "next";
22const nextConfig: NextConfig = {
23 logging: { fetches: { fullUrl: true } },
24};
25export default nextConfig;
26
27// Useful commands
28// next dev --inspect server breakpoints
29// next build --debug-prerender readable prerender errors
30// next info environment details for bug reports

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the Next.js set.

Open in study app