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 --inspectattaches the Node.js inspector to the process that runs your code (replacing the oldNODE_OPTIONS=--inspectworkaround). Openchrome://inspector 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.login 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: trueinnext.configlogs everyfetchwith cache hits and misses.
Client-side
- Browser DevTools: Sources breakpoints, Network (filter
_rscfor 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.causechains. - Next.js DevTools (the indicator button): route info, Cache Components insights, Navigation Inspector to pause at the loading state.
next build --debug-prerenderfor readable prerender errors;--debug-build-pathsto build a subset.next infofor bug reports.- MCP: the dev server exposes
/_next/mcpso coding agents can read errors, routes and logs.
Code example
tsx
1// .vscode/launch.json2// {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// }1920// next.config.ts - see fetch cache behavior in the terminal21import type { NextConfig } from "next";22const nextConfig: NextConfig = {23 logging: { fetches: { fullUrl: true } },24};25export default nextConfig;2627// Useful commands28// next dev --inspect server breakpoints29// next build --debug-prerender readable prerender errors30// 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.