I have the same problem, but resolved by two steps:
Add a line in VSCode settings.json: "debug.javascript.usePreview": false
Don't use NODE_OPTIONS="--inspect"
Then you may still see unbound breakpoint, but run the app and set the breakpoint again, it will be red and works well.
Update
Sometimes, I still have problem with setting breakpoint on API, so I took a few hours to figure out what's the real problem. Finally I found the issue:
Because when you run a Nextjs app, Node will first run next script, then next script will spawn a child process which is your own code. Nextjs also automatically set NODE_OPTIONS=--inspect when you use dev mode, but it use different port number and the number changes automatically. The KEY POINT is: The Next script and the child process will have different debugging port number. That is the reason that you sometimes can't set breakpoints.
There are some scenarios:
- If you start your server manually in VSCODE terminal by type "npm run dev", VSCODE will
automatically find the debugging ports and you will be fine.
- If you start your server outside of VSCODE from a terminal, and then use
attach, VSCODE will only attach one port, usually only attached to
Nextjs script. That's why you can't set breakpoint in you own code.
- If you use
launch method to start server in launch.json. Then same
problem will happened like No.2, You can't set your breakpoint.
There is a simple way to solve the problem: Either start server from VSCODE internal terminal or in launch.json, add:
"autoAttachChildProcesses": true,
then you can start debugging by hit F5 and everything going well.
{
"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"
},
"autoAttachChildProcesses": true,
}
You don't need to add NODE_OPTION='--inspect', neither "debug.javascript.usePreview": false
launch.jsonthat's there, running the debug server-side configuration, and setting a breakpoint on your API route?Click inspect under your application to open a separate DevTools window, then go to the Sources tabwhich does not seem useful for debugging server side code at specific points of execution.