Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
1 reply
Dave

Vscode debugging Nextjs serverside code - debugger does not refresh code (breakpoints hit old code)

When I debug server side Nextjs code (api routes) my breakpoints in Vscode do not work correctly.
I cant set breakpoints on most lines and they are jumping in debug.
Additionally the debugger stops at code that is not even invoked, so it seems to hit old code.
For example it stops at code from a function that I used before but I already changed the code to invoke a different function, so it seems the debugger uses "old code".

This does not happen in client side code so it seems to be a problem with server side.
It happens in trpc procedures as well as normal api routes.
It only happens in imported functions, so when I import functions from other files -> breakpoints in the api route / procedure file itself work.

My launch script (default from the Nextjs Docs)
{
  "version": "0.2.0",
  "configurations": [    
    {
      "name": "Next.js: debug full stack",
      "type": "node-terminal",
      "request": "launch", 
      "command": "npm run dev",
      "serverReadyAction": {
        "pattern": "started server on .+, url: (https?://.+)",
        "uriFormat": "%s",
        "action": "debugWithChrome"
      }
    }
  ]
}
Was this page helpful?