142

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.

5
  • You should already have node and npm under PATH when installed properly. What OS are you using, and how did you install them?
    – E_net4
    Jun 14, 2016 at 22:32
  • Yeah thats what I thought. I'm on Windows 10. I went here -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, 2016 at 22:44
  • 5
    Just in case other people have my problem: quitting and reopening fixed this for me. Oct 13, 2020 at 0:14
  • Restarting VS Code works, but the issue resurfaces time to time. How do I make this no longer an issue? I don't want to restart vs code and lose my typing history in some cases.
    – Sam Araiza
    Jul 13, 2022 at 18:20
  • Same thing happened to me after updating the MacOS system update, as others pointed out restarting the VSCode worked.
    – Faisal Ali
    Dec 14, 2022 at 20:08

21 Answers 21

215

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

Before you despair git that a try.

12
  • 21
    I had to re-run Shell command: Install 'code' command in PATH. before restarting VSCode: (CMD+SHIFT+P and start typing command name)
    – snajahi
    Nov 14, 2019 at 11:35
  • 5
    This is correct (for my case). And sadly, I've run into this mulitple times and I keep coming back to your answer. Thanks @David Nov 10, 2020 at 18:50
  • 3
    I tried restarting VSCode and that didnt work for me. Restarting my computer worked. I'm also on MacOS big sur on an M1 Mac Jun 3, 2021 at 23:24
  • 2
    While restarting VSCode works, it reoccurs from time to time. After restarting you lose your history and can no longer undo. It's a pretty annoying bug.
    – Sam Araiza
    Mar 10, 2022 at 23:53
  • 2
    Make sure to completely quit the application (by right click->quit on the Dock) and not just click the red close button.
    – kuzdogan
    Jul 6, 2022 at 10:18
107

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.

2
  • 1
    Genius. Also to mention, its a good practice to install node using nvm. Feb 15, 2021 at 20:16
  • 2
    Got this after running: " sudo: code: command not found"' Mar 9, 2021 at 5:39
43

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.

4
  • 3
    What about portable setup without adding node to the PATH, is there anyway to deal with that, seems a terrible restriction to me.] Aug 26, 2016 at 6:58
  • 1
    This was my problem. I avoided a restart by starting a new command prompt and launching vs code from the command prompt Aug 14, 2017 at 4:08
  • Configure PATH required restart on windows (which is mentioned in installation wizard) Jan 13, 2018 at 13:36
  • did not work for me
    – aj go
    Mar 3 at 7:28
43

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.

3
  • 1
    This worked for me. Thanks! Can you explain more?
    – Son Tr.
    Dec 4, 2020 at 1:59
  • 2
    If for example, you use nvm, running vscode from your current terminal profile (code .) will inherit from it the nvm configuration you probably have configured in .bashrc or .zshrc that points to the correct node binary Apr 25, 2022 at 17:24
  • 1
    Thank you this was the only thing that worked for me
    – Neil
    Sep 14, 2022 at 20:53
26

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 16 (change 16 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.

4
  • 1
    don't forget to restart vscode afterwards
    – mohas
    Jun 11, 2022 at 15:01
  • NVM has been my go-to for testing purposes between versions.
    – klewis
    Jun 15, 2022 at 19:44
  • 2
    just doing nvm alias default 16 in my case did the trick with a VSCode restart
    – A. Masson
    Aug 5, 2022 at 16:02
  • 1
    Seems this works for me. Not sure why node worked in terminal. But code can't recognize it. Waste quite some time to troubleshoot it. Feb 6 at 6:16
24

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

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

2
  • which json file? Jun 30, 2022 at 7:43
  • @captainblack launch.json
    – Dudi
    Jun 30, 2022 at 12:11
14

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

10

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

3
  • 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, 2016 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, 2016 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, 2016 at 12:46
7

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"
6

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.

0
5

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.

3

Just relaunch your project from the termial

e.g. yourprojectdir code .

2

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

1
  • 3
    its irrelevant, its about your session which need to be restarted: you just have to logout then log back . no need to restart computer Feb 17, 2017 at 14:09
2

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.

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!

3
  • 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 9, 2020 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 . Jun 9, 2020 at 21:43
  • debug.javascript.usePreview is no longer available starting from VSCode 1.60.0. Check out options on how to use the legacy debugger in This answer
    – sorjef
    Sep 9, 2021 at 17:02
2

(CMD+SHIFT+P) Shell command: Install 'code' command in PATH

should do the trick!

1
  • Maybe after a restart, though restarting generally fixes this issue for me. Hopefully this is a permanent fix and I won't be required to keep restarting VS Code.
    – Sam Araiza
    Jul 13, 2022 at 18:33
1

i resolved this problem after disable ESLint extention.

1

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

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

but this DID work:

code . -data-dir='.'
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

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.
0

Mine was more project specific. We use "Auto Reload" to run our launch.json for the backend. The error states the file path of the runtimeExecutable and allows you to open launch.json. In my launch.json case:

"runtimeExecutable": "${workspaceFolder}/functions/node_modules/.bin/nodemon"

I tried the restarts and answers here originally but no luck, so I manually explored into my functions/node_modules folder and realized .bin was missing. I used my terminal to path into functions like so:

   cd functions

   Terminal directory path example: ( ~/OneDrive/Desktop/{project dir covered}/{project dir covered}/functions )

Then I did an npm install using npm i, and now everything is back to normal. Keep in mind, most of these answers are general fixes. If your situtation is more specific, be sure to break it down from the start. Hope this might help others!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.