Reputation: 870
I installed nodejs on wsl following this steps:
https://learn.microsoft.com/en-us/windows/dev-environment/javascript/nodejs-on-wsl
Then debugging a helloworld example as shown here: https://code.visualstudio.com/docs/nodejs/nodejs-tutorial#_debugging-your-node-application
So I'm simply having in file helloworld.js
at the root of the vscode workspace dir
containing:
var msg = 'Hello World';
console.log(msg);
with a breaking point on console.log
Then on debug tab I click "create a launch.json file" which give me the default config:
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/helloworld.js"
}
But when I press F5
the activity bar debug button makes a *blip* but nothing happens and no error message on any tab appears (integrated terminal, debug console, problems, output)
It's only when I specify to vscode where to get the node binary path by adding to the config:
"runtimeExecutable": "/home/user01/.nvm/versions/node/v14.18.0/bin/node"
Then I get my code running and my breakpoint honored.
I thought it might be a problem of vscode not being able to find the path in a non-interactive shell so I tried as found here create a /etc/profile.d/nvm-autoload.sh
with the following:
# Enable nvm if available
if [ -f ~/.nvm/nvm.sh ]; then
source ~/.nvm/nvm.sh
fi
But still not...
And the runtimeExecutable
fix creates complications if I want to debug typescript files as it requires tsc: build
as a preLaunchTask
I could run my typescript debugger along a tsc -w
and getting ride of the preLaunchTask
but I feel something is wrong somewhere and that's bugging me...
Upvotes: 1
Views: 3394
Reputation: 1
I had a similar issue and fixed it by installing the WSL extension in VSCode.
Then, restart VSCode by running the following command at your project root in a WSL Terminal :
code .
Node debugging should work properly.
Upvotes: 0
Reputation: 870
The issue was due to the fact that I was starting Vscode from Windows start menu which don't set the environment variable properly.
To make it work I have to start vscode from wsl terminal.
cd ~/my/project
# if needed
nvm use
code .
then launch.json
mentionned above works
Upvotes: 9