Npm global 没有被使用? [英] Npm global not being used?
问题描述
所以我之前遇到了一些 npm 问题,并遵循了一些 stackoverflow/github 问题命令来尝试修复它们.哪个有效......有点.一切都很好,直到最近我意识到我的全局 npm 包实际上并没有被读取/使用.
So I've previously had some npm issues and followed some stackoverflow/github issues commands to attempt to fix them. Which worked... Kinda. Everything was fine until recently when I realised that my global npm packages are not actually being read/used.
所以每当我执行 npm -g install xxx 或更新时.它可以更新全局文件夹,但它只是没有被使用.于是我去挖了一下,发现了这个.
So whenever I did a npm -g install xxx, or an update. It updates the global folder alright, but it's just not being used. So I went to dig a little and found this.
npm 从哪里读取/使用
Where npm is reading/using from
usr/local/lib/node_modules
全局安装到哪里
Users/Me/.npm-global/lib/node_modules
因此,每当我对我的模块和内容进行 -g 检查时,一切都很好并且已更新,但是当我实际尝试运行任何内容时,npm 命令会使用旧文件夹中的那个.所以基本上我无法使用 -g 更新或安装任何东西.旧文件夹中没有任何内容,这是实际使用的文件夹.
So whenever I did a -g check for my modules and stuff, everything is good and updated, but when I actually try to run anything, the npm command uses the one in the older folders. So basically I can't update or install anything using -g. And nothing goes into the old folder which is the one being actually used.
我该如何解决这个问题?某些链接或个人资料是否被搞砸了?
How do I resolve this? Was some linking or profile got screwed?
推荐答案
看起来这与您的 npm 前缀配置有关.Global Prefix 是 npm 将安装全局包的文件夹.
It looks like this is about your npm prefix configuration. Global Prefix is the folder where npm will install global packages.
首先我会运行以下命令来获取全局前缀的值 (https://docs.npmjs.com/cli/prefix)
First I would run the following command to get the value of the global prefix (https://docs.npmjs.com/cli/prefix)
$ npm prefix -g
要将其设置为不同的值:
To set it to a different value:
npm config set prefix /usr/local/lib/node_modules
这是用于全局包的位置,现在您需要检查终端 PATH 变量是否正在检查此文件夹中的二进制文件.
This is for the location of your global packages, now you need to check that your terminal PATH variable is checking this folder for binaries.
$ echo $PATH
上面的命令将打印一个以:"分隔的文件夹位置列表,您的 shell 检查二进制文件.
Command above will print a ":" separated list of folder location that your shell checks for binaries.
您的全局 npm 前缀位置应该是该列表的一部分,根据您的问题,我假设此文件夹/usr/local/lib/node_modules 已经是.
Your global npm prefix location should be part of that list, from your question I'd assume this folder /usr/local/lib/node_modules already is.
这篇关于Npm global 没有被使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!