Reputation: 1
Visual Studio Code (VCS) upgraded to 1.89.0 on 5/1/2024 automatically on my system. Decided to upgrade my Node.JS from v16.20.2 to v18.20.2. I had the auto-attach debugger set as 'Always' in VSC, and it was working fine (hitting breakpoints) with Node v16.20.2, but it stopped working (breakpoints showing as unbound/grayed out) when I upgraded to Node v18.20.2, so I had to downgrade the Node back to v16.20.2 then the auto-attach and breakpoints work as expected again. There seems to be some issue with that version of VCS and Node V18 is not auto-attaching. Is there a different setting I have to add to make it work? Or perhaps we have to report the issue to Visual Studio Code team so they can fix it. Any suggested workarounds will be appreciated! Thanks!
I have my package.json with a script setup to use nodemon pointing to the app.js file
"scripts": {
"start": "node --trace-deprecation --trace-warnings ./amplify/backend/function/kuarxbedevFunction/src/app.js",
"startwithtrace": "node --trace-warnings ./amplify/backend/function/kuarxbedevFunction/src/app.js",
"server": "nodemon ./amplify/backend/function/kuarxbedevFunction/src/app.js"
},
I run my Node.js with the "npm run server" command in a VSC git bash terminal. I also tried running in it from a powershell terminal "npm run server", non of them worked.
When in Node V16 when running the npm run server, VCS is able to attach the debugger automatically to my app.js program. My launch.json does not have any setup related to node debugging, VSC was able to automatically attach to my Node.
When I upgraded to Node v18, the auto attach is no longer working, however the console shows in the log that the debugger is in fact attached, but somehow if I add a breakpoint to the code it is grayed out (showing the unbound error when I hover on it). I tried several configuration options in the launch.json file, and I was able to make it work with the option of "Node.js attach to process" but this option I have to run the "npm run server" in the terminal first and then select the Configuration in the debugger and click the play button, and then it shows several nodes processes running and I have to pick the correct one, and then it attached successfully, however those are many clicks to attach the debugger every time I'm running it, when in Node V16 it attached automatically without any manual steps, I will love to make the auto-attach work again with Node v18, otherwise, I prefer to stay in Node V16 for now.
If anyone has found a solution to make VSC debug auto-attach with Node v18, your suggestions are appreciated! Thanks!
Upvotes: 0
Views: 997
Reputation: 1
I found this launch.json
worked for me with Node 20.15.1 (this is the same as an automatic debug configuration for Node.js):
{
"version": "0.2.0",
"configurations": [
{
"type": "node-terminal",
"name": "Debug",
"request": "launch",
"command": "npm run dev",
"cwd": "${workspaceFolder}"
}
]
}
Upvotes: 0
Reputation: 365
Not a VSCode expert by any means, but breakpoints in Node suddenly stopped working for me last week VS Code v.1.89.1
using Node v22.2.0 (Windows)
and I was able to fix it by removing the "integratedTerminal" setting in my launch config and watching my debug logs in the "Debug Console" tab instead of the "Terminal" tab.
{
"type": "node",
"name": "server",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run",
"dev"
],
"restart": true,
//"console": "integratedTerminal",
"outputCapture": "std",
"internalConsoleOptions": "neverOpen"
},
Surely I'm breaking something else that I got working by using "integratedTerminal" in the past, but I need the breakpoints today so rolling the dice.
Hope this works for you.
Upvotes: 0