Debugging client-side React code in Chrome DevTools (Cmd + Option + I -> Sources -> Cmd + P) is straightforward, while Next.js server components and route handlers need Node's inspector attached.

Exposing the server debuggers

Starting Next.js with --inspect opens two inspector sockets, one for the router process and one for the Next server:

Debugger listening on ws://0.0.0.0:9229/...
Debugger listening on ws://0.0.0.0:9232/...

You can attach directly from the terminal with node inspect --port=9232 to hit debugger; statements inside Server Components, or wire both server and browser targets into VS Code.

VS Code launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Server",
      "type": "node",
      "request": "attach",
      "remoteRoot": "/app",
      "port": 9232,
      "address": "localhost",
      "localRoot": "${workspaceFolder}",
      "skipFiles": ["<node_internals>/**"],
      "autoAttachChildProcesses": false
    },
    {
      "name": "Client",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:3000",
      "webRoot": "${workspaceFolder}"
    }
  ]
}

Watch out for autoAttachChildProcesses

When running Next.js inside Docker, leaving VS Code's autoAttachChildProcesses enabled can trigger strange crashes inside child workers trying to preload a host-only ms-vscode.js-debug bootloader path (MODULE_NOT_FOUND: .../bootloader.js) or bogus worker retry errors in the browser. Adding "autoAttachChildProcesses": false to the attach config fixed it.