67

With a downloaded and installed version of Visual Studio Code 1.2.1, and a 64bit version of node.exe msi placed in my working directory (I am assuming that is correct), how do we add node and npm command line tools to be on our PATH? I am confused in understanding that statement. Where and how do we implement that? I am quoting this requirement directly from the top of this resource page - https://code.visualstudio.com/Docs/runtimes/nodejs

As a result of my current situation, I set a break-point in an app.js file. And when I hit F5, it tells me...

Cannot find runtime 'node' on PATH 

I am completely lost in understanding and fixing this issue in Visual Studio Code.

klewis
  • 5,905
  • 9
  • 52
  • 89
  • You should already have `node` and `npm` under PATH when installed properly. What OS are you using, and how did you install them? – SE_net4 the downvoter Jun 14 '16 at 22:32
  • Yeah thats what I thought. I'm on Windows 10. I went here -https://nodejs.org/en/download/ and downloaded the windows binary into my working folder. I then use the Command Line from within VSC to check if node --help works, and it does. But when I hit F5 to debug a .js file, I get this error. If i missed a step, please correct me. Thanks – klewis Jun 14 '16 at 22:44
  • Just in case other people have my problem: quitting and reopening fixed this for me. – Dashiell Rose Bark-Huss Oct 13 '20 at 00:14

18 Answers18

64

first run below commands as super user sudo code . --user-data-dir='.' it will open the visual code studio import the folder of your project and set the launch.json as below

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/app/release/web.js",
            "outFiles": [
                "${workspaceFolder}/**/*.js"
            ],
            "runtimeExecutable": "/root/.nvm/versions/node/v8.9.4/bin/node"
        }
    ]
}

path of runtimeExecutable will be output of "which node" command.

Run the server in debug mode cheers

regendo
  • 1
  • 1
anuj rana
  • 664
  • 5
  • 2
44

On OSX and VSCode 1.56.2 all I had to do was to close and restart VSCode and the problem went away.

David Dehghan
  • 14,410
  • 2
  • 84
  • 85
36

To follow up, I just ran into this as well. When I installed Node.js there was an option that said Add to PATH (Available After Restart). Seems like Windows just needs a restart to make things work.

16

Quick fix that works for me. Navigate to the root directory of your folder from command line (cmd). then once you are on your root directory, type:

code . 

Then, press enter. Note the ".", don't forget it. Now try to debug and see if you get the same error.

Afzaal Ahmad Zeeshan
  • 14,868
  • 10
  • 50
  • 94
11

So node got kicked out of path. you can do

       SET PATH=C:\Program Files\Nodejs;%PATH%

Or simply reinstall node to fix this. which ever you think is easiest for you

irimawi
  • 340
  • 1
  • 9
  • Thanks for the quick tip! If I set path, do I write out that exact line out in my command prompt? or within a file? thanks for the direction on this. – klewis Jun 14 '16 at 22:35
  • This can be written via command line, just be careful as you might need double quotes in the path – irimawi Jun 14 '16 at 22:42
  • I'll give it a shot tonight. Thanks for the quick help again! – klewis Jun 14 '16 at 22:42
  • This is so funny - sense 6:00pm last night, I put my windows 10 laptop to sleep. woke it up this morning at 8:44am and made another attempt to F5 my javascript file. And now the debugger works. Looks like the path was off like you said, but it appears the application corrected itself...? strange. – klewis Jun 15 '16 at 12:46
9

I did which node on my terminal: /usr/local/bin/node

and then i added "runtimeExecutable": "/usr/local/bin/node" in my json file.

ASHISH RANJAN
  • 3,171
  • 1
  • 17
  • 11
6

For me, the node binary is in PATH and I can run it from the terminal (iTerm or Terminal), and the Terminal apps are set to use zsh

If you are on a Mac, with iTerm and Zsh, please use the following VSCode settings for Node to work.

After this change, you can get rid of this line from your launch.json config file. (the debug settings in VSCode)

    "runtimeExecutable": "/usr/local/bin/node"

If this doesn't work, make sure you choose the default shell as zsh. To do this,

  • Open the command palette using Cmd+Shift+P

  • Look for the Terminal: Select Default Shell command enter image description here

  • Select zsh from the options enter image description here

Aditya Vikas Devarapalli
  • 2,359
  • 1
  • 28
  • 46
5

Had the same issue and in my case it was a problem with a vs code extension. Try running code as:

$ code --disable-extensions

Once in the editor, I ran my program in the debug mode and worked, and then started code with

$ code

And it continued working fine.

Hope it works for you.

Duck Dodgers
  • 3,126
  • 6
  • 25
  • 38
Sebastian
  • 101
  • 2
  • 3
  • After updated to macOS Catalina this is the only thing that worked for me. Thank You! – Shl Apr 07 '20 at 16:20
5

I had a similar issue with zsh and nvm on Linux, I fixed it by adding nvm initialization script in ~/.profile and restart login session like this

export NVM_DIR="$HOME/.nvm" 
 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm 
 [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
salamaashoush
  • 152
  • 1
  • 6
3

I use /bin/zsh, and I changed vscode to do the same, but somehow vscode still use the path from /bin/bash. So I created a .bash_profile file with node location in the path.

Simply run in terminal:

echo "PATH=$PATH
export \$PATH" >> ~/.bash_profile

Restart vscode, and it will work.

Shl
  • 1,414
  • 11
  • 13
2

I also ran into this error. Restart the PC works for me.

Umair Akbar
  • 378
  • 3
  • 10
2

The cause for me receiving this error was trying the new pre-release VSCode JS debugger.

If you opted in, change via User settings:

    "debug.javascript.usePreview": true|false

Everything in my normal configuration and integrated terminal was correct and finding executables. I wasted a lot of time trying other things!

Sean Patrick Murphy
  • 2,371
  • 23
  • 16
  • I am using vscode insiders version 1.46.0-insider, but I had to set this to `false` in order to get the debugger to hit breakpoints. I am using the jasmine-test-explorer. Now I just need to figure out why the node version isn't being picked up from my NVM installation; instead, it is using the bundled node version with vscode. – alex Jun 09 '20 at 14:58
  • Hmm in that case you can try specifying `runtimeVersion` to match what Node environment you're using. Others have also said launching code from the command line picks up environment more reliably, e.g. `cd project` then `code-insiders .` – Sean Patrick Murphy Jun 09 '20 at 21:43
1

Do not launch the VS code from the start menu separately. Use

$Code .

command to launch VS code. Now, create your file with the extension .js and Start debugging (F5) it. It will be executed.

Otherwise, restart your system and follow the same process.

0

i resolved this problem after disable ESLint extention.

0

I am on OSX, this did not work for me:

code . --user-data-dir='.'

but this DID work:

code . -data-dir='.'
Pauls Bebris
  • 169
  • 2
  • 4
0

This is the solution according to the VS code debugging page. This worked for my setup on Windows 10.

"version": "0.2.0",
"configurations": [
{
    "type": "node",
    "request": "launch",
    "name": "Launch Program",
    "program": "${file}"
}

The solution is here:

https://code.visualstudio.com/docs/editor/debugging

Here is the launch configuration generated for Node.js debugging

D.L
  • 661
  • 4
  • 15
0

I also encountered this issue. Did the following and it got fixed.

  1. Open your computer terminal (not VSCode terminal) and type node --version to ensure you have node installed. If not, then install node using nvm.
  2. Then head to your bash file (eg .bashrc, .bash_profile, .profile) and add the PATH:
 [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm 
 [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
  1. If you have multiple bash files, you ensure to add the PATH to all of them.
  2. Restart your VSCode terminal and it should be fine.
Obinna Nnenanya
  • 611
  • 9
  • 11
0

Apply a Default Node Version via NVM

I'm using macOS Big Sur and setting the default version via nvm fixed this for me by running this command: nvm alias default 14 (change 14 to the version you want as your default).

Note that node worked fine in the terminal for me (both with zsh and bash) but not when running via the vscode debugger and I already had the following config in both ~/.zshrc and ~/.bash_profile to load in nvm:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

It wasn't until I set the default Node version that vscode would launch node targets just fine.

Sam
  • 25,752
  • 12
  • 68
  • 97