如何包含节点二进制npm的路径已执行

Jeb*_*b50 44 node.js npm

Windows,VSC,Running npm start得到了这个

npm WARN生命周期用于脚本的节点二进制文件是C:\ Program Files \nodejs \node.exe,但是npm使用的是C:\ somewhere\AppData\Roaming \npm \node_modules \node\bin \node.exe本身.使用该--scripts-prepend-node-path选项可以包含执行的节点二进制文件npm的路径.

我理解这意味着我的本地版本是PATH变量(C:\ Program Files ...)中的差异.如何继续告诉它使用--scripts-prepend-node-path

我通过替换PATH变量中的C:\Program Files\nodejswith C:\somewhere\AppData\Roaming\npm\node_modules\node\bin来玩一个技巧,它确实获得了新的node.exe but there is no node binary in the current PATH.再次建议使用该--scrip ts-prepend-node-path选项来包含执行的节点二进制文件npm的路径

Jeb*_*b50 62

就像我说的,替换PATH系统变量中的实际路径并没有完全解决问题,它抱怨二进制文件丢失了.发现解决了there is no node binary in the current PATH问题,工作.恢复原来的PATH,也工作了.

scripts-prepend-node-path=true是关键,只需在应用程序的根文件夹中创建一个文件,名为.npmrc,将此行放入其中解决了问题:

there is no node binary in the current PATH

  • 不知道为什么,但这对我有用,但下面的“npm config set templates-prepend-node-path auto”命令答案却没有。谢谢。 (4认同)
  • 此选项已在最近的 npm 中删除:https://github.com/npm/cli/issues/2808 (3认同)

god*_*out 36

这是另一种可行的方法: npm config set scripts-prepend-node-path auto

  • 接受这个作为接受的答案,因为a)它有效(在我的所有环境中)并且b)正如@kas指出的那样,它让生活变得更轻松。 (3认同)

Lio*_*rom 9

您的节点二进制文件和您的npm之间的冲突


npm 正在尝试使用与其用于运行自身的节点相同的节点。

要解决此冲突,请尝试运行:

npm config set scripts-prepend-node-path true
Run Code Online (Sandbox Code Playgroud)


Ron*_*omb 5

在Visual Studio 2017中存在此问题,我改为告诉VS始终使用从nodejs.org安装的NodeJS,而不要使用Visual Studio随附的即时冻结版本。(VS2015附带的那个版本太旧了,无法再使用了。)

在Visual Studio中,转到“工具”>“选项”>搜索“外部Web工具”>,并确保“ C:\ Program Files \ nodejs”(或在安装了nodejs.org的位置)位于路径列表中的第一位,并在必要时添加它。