VSCode Nodejs debugger does not save changes? - node.js

I am just starting to learn using the Nodejs debugger. It has been really helpful already but I spent a a lot of time changing a js file I was debugging but I did not know that the changes I made were not being implement right away.
Is this an expected behavior? Can I set the debugger up so that it restarts on each save and notices the new changes?
Edit 1 :
Here is my debuf config:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\app.js"
}
]
}

Normally, after every save, you have to restart your node program to see the changes. I'm sure there are other programs but one I use exclusively (I never use node alone) is nodemon. It's globally installed npm package program. Here is sample config for vs code debugger:
{
"type": "node",
"request": "launch",
"name": "Launch app - nodemon",
"runtimeExecutable": "nodemon",
"runtimeArgs": [
"--inspect=9250"
],
"program": "${workspaceRoot}/api/app",
"cwd": "${workspaceRoot}/api",
"autoAttachChildProcesses": true,
"restart": true
},
nodemon will monitor all the files and restart node every time it detects changes.
Add runtimeArgs to change debugger port.

Related

Node Debugging in WSL

I am using Windows 10 WSL in VSCode.
I have the extensions remote development, WSL, I have node installed, nvm as well.
When in work in a remote WSL and try to debug I don't have the Node option at all.
When I run the file I get:
No debugger available, can not send 'variables'
My launch.json is as follows:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
}```
Can someone please help me fix it by adding Node.js option so I can properly debug?
Thanks a lot in advance!
Did you found the solution eventually?
I add similar issue, I could get things working only by specifying the node binary path explicitly.
get your node binary path by issuing:
which node
then add it to your launch.json config:
{
"name": "Launch Program",
"program": "${workspaceFolder}/helloworld.js",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"type": "pwa-node",
"runtimeExecutable": "/home/user01/.nvm/versions/node/v14.18.0/bin/node"
},
Still there is something is wrong going on, even though I simply the setup tutorial:
https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl

only shown legacy and preview options for debugging node.js

I am currently trying to start a node.js project is VSCode, and I want to set up the debugger with a launch.json file. I understand the way to do this is to go to run -> add configuration, but when I do so, there is no option to select the "Node.js" environment specifically (there is Node.js (legacy) and Node.js (preview) as shown in the screenshot attached). I'm currently on v10.15.1 (in another project I am able to debug in a 'pure' Node.js environment, where the type property of configurations in launch.json is set as "node") - is this supposed to cause issues?
this stackoverflow post can help you.
In summary, legacy and preview means old and new nodejs debugger in vscode, respectively.
The following json snippets show the difference between launch.json files using the two debuggers, and only the type field differs.
// node-preview
"configurations": [
{
"type": "pwa-node", //differs
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]
//node-legacy
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
}
]

VS Code Debugging for Node.js not working

For some reason the VS Code debugger doesn't stop at breakpoints in recently created node.js projects. In some of my older projects it works like a charm. I use the same launch files but it wont work. The debugger starts and runs through but it doesn't stop on any breakpoints.
Someone had the same issue? I recognized this after the latest update but I can't find some forum entries describing my problem.
I'm running the VS Code Version 1.50.1 and Node.js Version 14.13.0.
This is the launch file of an older project which works:
{
"type": "node",
"request": "launch",
"name": "Launch LN Star",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}\\NL_Star\\main.js",
"console": "integratedTerminal"
}
This is the launch file of a new project which runs but doesn't stop on any breakpoint
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}\\index.js",
"console": "integratedTerminal"
}
]
}
I'm glad to add some more information if needed and when I know how or where to look for it. But for now I don't really know where to start to fix this.
I guess I just missed something but I cant really find it!
Thanks a lot in advance for your help!

Error coming while debugging my typescript file:-> Debugger attached. Waiting for the debugger to disconnect

I have gone through plethora of articles online ,I have tried every possible way given online for this but nothing has worked for me till now.
I have reinstalled node,vs code,npm all again but nothing is working.
I am using ->
VSCode Version: 1.27.2
OS Version: Windows 10 Pro 64bit OS,x64-based processor
Node version: v8.11.3
My launch.json is as follows:-
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/dist/LeonardoGrader.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/dist/**/*.js"]
}
]
}
Any help will be appreciated.Thanks in advance.
That output means that your program ran to completion without ever stopping in the debugger. Either set some breakpoints or change the stopOnEntry option to true to stop the program on the first line of code.

VSCode Debugger pauses unexpectedly in node modules files

While running my nodejs server code through the VSCode Debugger it pauses weirdly in multiple node module library files. Then I just have to hit play button like a hundred times to finally run the whole code. This is so annoying. I have no idea how to fix it. I even tried skipping node module files and folder in launch.json file but it just doesn't seem to work. Below is my launch.json file.
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${file}",
"cwd": "${workspaceRoot}",
"skipFiles": [
"${workspaceRoot}/node_modules/**/*.js",
"<node_internals>/**/*.js"
]
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"address": "localhost",
"port": 5858
}
]
}
uncheck them and it will work smoothly

Resources