简体   繁体   English

IDE 在 PATH 中找不到节点二进制文件,但在“echo $PATH”期间显示(Ubuntu Linux)

[英]Node binary not found in PATH by IDE, yet shows during `echo $PATH` (Ubuntu Linux)

VSCode shows the following alert in a prompt: VSCode 在提示中显示以下警告:

Can't find Node.js binary "node": path does not exist.找不到 Node.js 二进制“节点”:路径不存在。 Make sure Node.js is installed and in your PATH, or set the "runtimeExecutable" in your launch.json确保 Node.js 已安装并在您的 PATH 中,或者在您的 launch.json 中设置“runtimeExecutable”

In terminal I see an NVM path to node:在终端中,我看到了到节点的 NVM 路径:

$ node --version
v12.18.4

$ echo $PATH
/home/owner/.config/nvm/versions/node/v12.18.4/bin
:/usr/local/sbin:/usr/local/bin:/usr/sbin
:/usr/bin:/sbin:/bin:/usr/games
:/usr/local/games:/snap/bin
// line breaks manually added by me for readability

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.5 LTS
Release:        18.04
Codename:       bionic

$ npm --version
6.14.6

Does anyone know how to fix this PATH issue?有谁知道如何解决这个 PATH 问题?

I suspect the issue is with PATH and not VsCode but am including my launch.json below in case I'm wrong.我怀疑问题出在 PATH 而不是 VsCode,但我在下面包含了我的 launch.json 以防我错了。

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "pwa-node",
      "request": "launch",
      "name": "Launch Program",
      "skipFiles": [
        "<node_internals>/**",
        "node_modules"
      ],
      "program": "${workspaceFolder}/src/server.ts",
      "preLaunchTask": "tsc: build - tsconfig.json",
      "outFiles": [
        "${workspaceFolder}/compiled/**/*.js"
      ],
      "runtimeExecutable": "node"
    }
  ]
}
Other Attempts to fix this 其他尝试解决此问题

Restarting Computer - The PATH issue still presented重新启动计算机- PATH 问题仍然存在

Adding / removing runtimeExecutable k/v pair from above config file - Also no change从上面的配置文件中添加/删除 runtimeExecutable k/v 对- 也没有变化

用这个更新launch.json

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

update "runtimeExecutable" in launch.json to:将 launch.json 中的“runtimeExecutable”更新为:

        "runtimeExecutable": "your-path/.npm-global/nodemon",

example :例子 :

        "runtimeExecutable": "C:/Users/bekir/.npm-global/nodemon",

The problem is your IDE does not find Node path in your computer.问题是您的 IDE 在您的计算机中找不到节点路径。

You first should find where you have Node installed, can be done using the echo command:您首先应该找到安装 Node 的位置,可以使用echo命令完成:

echo node

And go to the launch.json file, and update the "runtimeExecutable" option to the path you got here.并将 go 添加到 launch.json 文件,并将"runtimeExecutable"选项更新为您在此处获得的路径。

launch.json file, example in Visual Studio Code: launch.json 文件,Visual Studio Code 中的示例:

{
  ...
  "configurations": [
    {
      ...
      "runtimeExecutable": "insert here the path returned by echo node",
      ...
    }
  ]
}

This is probably not the most elegant solution but I redundantly installed nodejs via terminal and this has fixed the PATH issue这可能不是最优雅的解决方案,但我通过终端冗余安装了 nodejs,这解决了 PATH 问题

sudo apt install nodejs

The debugger is showing the path to the node binary in the subfolder of nvm so I'm not clear what changes were made, other than it works now.调试器在nvm的子文件夹中显示了节点二进制文件的nvm所以我不清楚做了哪些更改,但现在可以正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM