javascript npm 在不同位置节点 js 上安装全局模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20144828/
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
Npm install global modules on different location node js
提问by Joey Hipolito
I am on a unix os, ubuntu, and I am experiencing a problem in installing global modules.
我使用的是 unix os、ubuntu,并且在安装全局模块时遇到问题。
When I tried to look up where the node_modules folder is, I found out that npm installed some of my global modules in
当我试图查找 node_modules 文件夹的位置时,我发现 npm 安装了我的一些全局模块
/usr/lib/node_modules
and some of them are installed in
其中一些安装在
/usr/local/lib/node_modules
I have no problem before on using this global modules, until such time I tried installing a generator, that is when I first thought of looking into the directories because, after installing the generator, it says that I haven't installed the generator.
在使用这个全局模块之前我没有问题,直到那时我尝试安装生成器,那是我第一次想到查看目录,因为在安装生成器后,它说我还没有安装生成器。
What is odd is that when I tried some of the modules, they work perfectly fine except for the other modules, saying it wasn't installed.
奇怪的是,当我尝试一些模块时,除了其他模块外,它们工作得很好,说没有安装。
Is there a way to uninstall/remove/clean my computer from nodejs including its module and install it again so that it will just be using a single directory, so there won't be any confusion.
有没有办法从 nodejs 卸载/删除/清理我的计算机,包括它的模块并重新安装它,这样它就只会使用一个目录,所以不会有任何混淆。
Why do you think npm installed this things in two diff. directories.
为什么你认为 npm 在两个不同的地方安装了这个东西。目录。
采纳答案by Jesper Blaase
It looks to me like you have had 2 different versions of nodejs installed. Probably a packaged version and then a new release?
在我看来,您已经安装了 2 个不同版本的 nodejs。可能是打包版本,然后是新版本?
It works because your node folder is probably set to /usr/local/lib/node_modules Node allways traverses the folder tree when looking for modules so if you do a require('imNotHere') it will look in:
它有效是因为您的节点文件夹可能设置为 /usr/local/lib/node_modules 节点在查找模块时始终遍历文件夹树,因此如果您执行 require('imNotHere') 它将查找:
/usr/local/lib/node_modules/imNotHere
/usr/local/node_modules/imNotHere
/usr/node_modules/imNotHere
/node_modules/imNotHere
before failing. In your setup modules in /usr/lib/node_modules will still be caught by this
在失败之前。在 /usr/lib/node_modules 中的设置模块中仍然会被这个捕获