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"
}
}
]
}
{
"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"
}
}
]
}
1 Reply
Dave
DaveOP3y ago
Ok I think I found the issue. The file of the imported function has line CRLF (as all files since I am on windows). When I change the line ending of the file to LF, debugging and breakpoints work again. I tested the line endings because of this thread in the Nextjs Github https://github.com/vercel/next.js/issues/32470 Maybe it helps other people with this issue. I will test it further but it seems to work now with line ending LF.
GitHub
Sourcemaps stop working due to multiline comment + CRLF line ending...
What version of Next.js are you using? Happens in at least 12.0.0, 12.0.7, 12.0.8-canary.5 and 12.0.8-canary.8. What version of Node.js are you using? 16.13.1 What browser are you using? Chrome Wha...

Did you find this page helpful?