node.js 如何包含节点二进制 npm 的路径被执行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51293566/
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
How to include the path for the node binary npm was executed with
提问by Jeb50
Windows, VSC, Running npm startgot this
Windows、VSC、Runningnpm start得到了这个
npm WARN lifecycle The node binary used for scripts is C:\Program Files\nodejs\node.exe but npm is using C:\somewhere\AppData\Roaming\npm\node_modules\node\bin\node.exe itself. Use the
--scripts-prepend-node-pathoption to include the path for the node binary npm was executed with.
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 的路径。
I understand it means my local version is diff from the one in the PATH variable (C:\Program Files...). How do proceed to tell it to use --scripts-prepend-node-path?
我知道这意味着我的本地版本与 PATH 变量 (C:\Program Files...) 中的版本不同。如何继续告诉它使用--scripts-prepend-node-path?
I played a trick by replacing the C:\Program Files\nodejswith C:\somewhere\AppData\Roaming\npm\node_modules\node\binin PATH variable, it does pick up that new node.exe got but there is no node binary in the current PATH. Again recommend to use the --scrip
ts-prepend-node-pathoption to include the path for the node binary npm was executed with
我通过更换捉弄C:\Program Files\nodejs与C:\somewhere\AppData\Roaming\npm\node_modules\node\bin在PATH变量,它并拿起新node.exe了but there is no node binary in the current PATH。再次建议使用--scrip
ts-prepend-node-path包含节点二进制 npm 的路径的选项
回答by Jeb50
Like I said, replacing the actual path in PATH system variable didn't fix the problem completely, it still complained about binary is missing. Found thissolved the there is no node binary in the current PATHproblem. Restored the original PATH, tried it worked.
就像我说的,替换 PATH 系统变量中的实际路径并没有完全解决问题,它仍然抱怨缺少二进制文件。发现这解决了there is no node binary in the current PATH问题。恢复了原来的PATH,试了一下。
Simply create a file at the root folder of the app, called .npmrc, place this line into it:
scripts-prepend-node-path=true
只需在应用程序的根文件夹中创建一个名为.npmrc 的文件,将此行放入其中:
scripts-prepend-node-path=true
回答by godbout
Here's another way that works: npm config set scripts-prepend-node-path auto
这是另一种有效的方法: npm config set scripts-prepend-node-path auto
回答by Lior Elrom
Conflict between your node binary and your npm
你的节点二进制文件和你的 npm 之间的冲突
In case the error looks something like:
如果错误看起来像:
npm is trying to use the same node as the one it use to run itself.
npm 试图使用与它用来运行自己的节点相同的节点。
resolve this conflict by adding the node directory to your PATH:
通过将节点目录添加到您的PATH:
npm config set scripts-prepend-node-path true
npm run sets the NODE environment variable to the node executable with which npm is executed. Also, if the --scripts-prepend-node-path is passed, the directory within which node resides is added to the PATH
npm run 将 NODE 环境变量设置为执行 npm 的节点可执行文件。此外,如果 --scripts-prepend-node-path 被传递,则节点所在的目录将添加到 PATH
回答by Ron Newcomb
Having this issue in Visual Studio 2017, I instead told VS to always use the NodeJS that I had installed from nodejs.org rather than the frozen-in-time one that ships with Visual Studio. (The one that shipped with VS2015 is so ancient it doesn't really work anymore.)
在 Visual Studio 2017 中遇到此问题,我改为告诉 VS 始终使用我从 nodejs.org 安装的 NodeJS,而不是 Visual Studio 附带的冻结时间。(VS2015 附带的那个太古老了,它不再真正起作用了。)
In Visual Studio, go to TOOLS > OPTIONS > search for EXTERNAL WEB TOOLS > and ensure "C:\Program Files\nodejs" (or wherever nodejs.org installed it) is first in the list of paths, adding it if necessary.
在 Visual Studio 中,转到 TOOLS > OPTIONS > search for EXTERNAL WEB TOOLS > 并确保“C:\Program Files\nodejs”(或 nodejs.org 安装它的任何地方)是路径列表中的第一个,必要时添加它。

