WSL + VS Code: VSCode assumes `node` versus `nodejs` binary name

Viewed 1633

My goal is to make Windows 10 + WSL a development platform for doing *IX style programming as good as what I've had on OSX for the last several years. I'm also trying new things along the way, including this new-fangled VS Code.

  • With WSL + Ubuntu I installed the nodejs package.
  • I create a "Hello World" in VS Code using JavaScript
  • I run the debug command

Cannot find runtime 'node' on PATH. Make sure to have 'node' installed.

Hrm. OK. I'm prompted to open up launch.json or close.

So I thought as a workaround to try adding an alias for node to nodejs.

I restarted VS Code, tried the same process, same failure.

I then tried a symlink between /usr/bin/node to /usr/bin/nodejs. Same error.

I would think this a pretty standard use case in the post-WSL era, but I've not found a canonical implementation nor have I seen "That's impossible!" so, here we are :)

2 Answers

I use nvm to install Node on Ubuntu, although it should work fine if you install it normally.

e.g.

nvm install 9.2.0
nvm alias default 9.2.0

From the VSCode docs

If you want to run Node.js in the Linux subsystem on Windows (WSL), you can use the approach from above as well. However to make this even simpler, we've introduced a useWSL flag to automatically configure everything so that Node.js runs in the Linux subsystem and source is mapped to files in your workspace.

Here is the simplest debug configuration for debugging hello.js in WSL: { "type": "node", "request": "launch", "name": "Launch in WSL", "useWSL": true, "program": "${workspaceFolder}/hello.js" }

The above didn't work for me, but the top answer here did: https://askubuntu.com/questions/1065276/cannot-find-runtime-node-on-path-in-visual-studio-code-running-installed-on-u?newreg=dbdc6529203049dc9106b3b1aa6c84e6

In short, there seem to be two options.

1 - (which worked for me) Using 'which node' in the VSCode terminal to get the path and then adding a "runtimeExecutable": "insert-path-you-got-here", line to the launch.json

2 - (which I haven't tried) adding nvm initialization script in ~/.profile (see the other answer in that link).

Related