如何包含节点二进制 npm 的路径被执行 [英] How to include the path for the node binary npm was executed with

查看:88
本文介绍了如何包含节点二进制 npm 的路径被执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows, VSC, Running npm start 得到这个

Windows, VSC, Running npm start got this

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

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-path option to include the path for the node binary npm was executed with.

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

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?

我把C:\Program Files\nodejs 替换为PATH 中的C:\somewhere\AppData\Roaming\npm\node_modules\node\bin变量,它确实接收到新的 node.exe 得到 ,但当前 PATH 中没有节点二进制.再次推荐使用 --scripts-prepend-node-path 包含节点二进制 npm 路径的选项是用

I played a trick by replacing the C:\Program Files\nodejs with C:\somewhere\AppData\Roaming\npm\node_modules\node\bin in 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-path option to include the path for the node binary npm was executed with

推荐答案

就像我说的,替换 PATH 系统变量中的实际路径并没有完全解决问题,它仍然抱怨缺少二进制文件.找到 this 解决了当前PATH中没有节点二进制的问题.恢复了原来的PATH,试了一下.

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 this solved the there is no node binary in the current PATH problem. Restored the original PATH, tried it worked.

只需在应用的根文件夹中创建一个名为 .npmrc 的文件,将此行放入其中:

Simply create a file at the root folder of the app, called .npmrc, place this line into it:

scripts-prepend-node-path=true

这篇关于如何包含节点二进制 npm 的路径被执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆