190

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? Commented 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 Commented Jun 14, 2016 at 22:44
  • 5
    Just in case other people have my problem: quitting and reopening fixed this for me. Commented 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. Commented 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. Commented Dec 14, 2022 at 20:08

26 Answers 26

323

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

Before you despair give that a try.

Sign up to request clarification or add additional context in comments.

14 Comments

I had to re-run Shell command: Install 'code' command in PATH. before restarting VSCode: (CMD+SHIFT+P and start typing command name)
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
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
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.
Make sure to completely quit the application (by right click->quit on the Dock) and not just click the red close button.
|
113

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.

6 Comments

Genius. Also to mention, its a good practice to install node using nvm.
Got this after running: " sudo: code: command not found"'
It's 2024 and I just tried this and it created all sorts of bad things in my working directory. I would say don't do this.
This is not a good recommendation to run vscode in sudo.
what if you switch your node version.. you'll have to remember and update the launch.json too?
|
52

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.

4 Comments

This worked for me. Thanks! Can you explain more?
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
Thank you this was the only thing that worked for me
44

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.

5 Comments

What about portable setup without adding node to the PATH, is there anyway to deal with that, seems a terrible restriction to me.]
This was my problem. I avoided a restart by starting a new command prompt and launching vs code from the command prompt
Configure PATH required restart on windows (which is mentioned in installation wizard)
did not work for me
@Perposterer Wow, that worked (closing VSC, then running code . in the terminal to open it). Crazyiness. But it's only temporary. After I closed VSC and opened it in the normal way, the original problems reappeared (of nvm node not being in the Path).
36

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.

5 Comments

don't forget to restart vscode afterwards
NVM has been my go-to for testing purposes between versions.
just doing nvm alias default 16 in my case did the trick with a VSCode restart
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.
i saw the error after installing more node versiones, this fix it propertly
27

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 Comments

which json file?
@captainblack launch.json
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

Comments

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

4 Comments

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.
This can be written via command line, just be careful as you might need double quotes in the path
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.
the Node to be installed is the application (from setup in nodejs.org), don't confuse with vscode extension (is not an extension).
8

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.

2 Comments

for some reason this actually works; txs
8

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"

Comments

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.

Comments

5

nvm alias default node (or the node version you use) and restarting VS Code solved it for me!

Comments

4

I found solution! Using Mac + NVM try this, the problem lies in launch.json file.

After saving launch.json, head to your .js file and press F5 or the green arrow beside Launch Program.

Inspect your outputs in DEBUG CONSOLE tab (below).

// launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${file}",
            "runtimeExecutable": "/Users/YOURMACUSER/.nvm/versions/node/v20.9.0/bin/node",
        }
    ]
}

*** You can check your node version with which node command in terminal, remember to replace your node version in v20.9.0 above

1 Comment

the only problem i see with this is that it's not reusable by a team.
3

Just relaunch your project from the termial

e.g. yourprojectdir code .

1 Comment

2

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

1 Comment

its irrelevant, its about your session which need to be restarted: you just have to logout then log back . no need to restart computer
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.

1 Comment

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 Comments

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

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

should do the trick!

1 Comment

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

I am using vscodium. I was launching it from the shell and had the same problem. I advise to install the right package for your distribution (e.g. .deb) and then open it through the shortcut.

Comments

2

What worked for me on windows 10:

  • intall the node.js
  • restart pc and visual studio code -open the file I want to run and select " run current file" as the run and debug function

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
1

i resolved this problem after disable ESLint extention.

Comments

1

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

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

but this DID work:

code . -data-dir='.'

Comments

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

Comments

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.

Comments

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!

Comments

0

Close the vscode and open the repo from terminal. Just open the terminal and cd to the repo and then do code .

That worked for me

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.