在 PATH 上找不到运行时“节点” - Visual Studio Code 和 Node.js

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37823194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:18:26  来源:igfitidea点击:

Cannot find runtime 'node' on PATH - Visual Studio Code and Node.js

node.jsvisual-studio-code

提问by klewis

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

下载并安装了 Visual Studio Code 1.2.1 版本和 64 位版本的 node.exe msi 放在我的工作目录中(我假设这是正确的),我们如何添加 node 和 npm 命令行工具我们的路径?我对理解该声明感到困惑。我们在哪里以及如何实施?我直接从这个资源页面的顶部引用了这个要求 - 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...

由于我目前的情况,我在 app.js 文件中设置了一个断点。当我按 F5 时,它告诉我...

Cannot find runtime 'node' on PATH 

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

我完全无法理解和解决 Visual Studio Code 中的这个问题。

采纳答案by Michael P. Scott

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.

为了跟进,我也遇到了这个问题。当我安装 Node.js 时,有一个选项说添加到 PATH(重启后可用)。似乎 Windows 只需要重新启动即可正常工作。

回答by anuj rana

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

首先以超级用户身份运行以下命令, sudo code . --user-data-dir='.'它将打开visual code studio 导入您的项目文件夹并设置launch.json如下

{
    "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.

runtimeExecutable 的路径将是"which node"命令的输出。

Run the server in debug mode cheers

以调试模式运行服务器

回答by Edson H Philippe

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:

对我有用的快速修复。从命令行 (cmd) 导航到文件夹的根目录。然后一旦你进入你的根目录,输入:

code . 

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

然后,按回车键。注意“.”,不要忘记。现在尝试调试并查看是否出现相同的错误。

回答by irimawi

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

或者干脆重新安装节点来解决这个问题。你认为对你来说最简单的

回答by David Dehghan

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

在 OSX 和 VSCode 1.30.0 上,我所要做的就是关闭并重新启动 VSCode,问题就消失了。

回答by ASHISH RANJAN

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

which node在我的终端上做了: /usr/local/bin/node

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

然后我添加 "runtimeExecutable": "/usr/local/bin/node"到我的 json 文件中。

回答by Sebastian

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

有同样的问题,就我而言,这是vs 代码扩展的问题。尝试将代码运行为:

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

希望对你有效。

回答by salamaashoush

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

我在 Linux 上遇到了类似的 zsh 和 nvm 问题,我通过在其中添加 nvm 初始化脚本~/.profile并重新启动登录会话来解决它

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"

回答by Umair Akbar

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

我也遇到了这个错误。重新启动 PC 对我有用。

回答by Sourav Debnath

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

不要单独从开始菜单启动 VS 代码。用

$Code .

$代码。

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

启动 VS 代码的命令。现在,创建扩展名为 .js 的文件并开始调试 (F5)。它将被执行。

Otherwise, restart your system and follow the same process.

否则,重新启动系统并遵循相同的过程。