首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么不能列出全球安装的npm模块?

为什么不能列出全球安装的npm模块?
EN

Stack Overflow用户
提问于 2015-11-12 16:49:20
回答 1查看 212关注 0票数 1

我在跑:

代码语言:javascript
复制
npm ls -g 

它没有显示任何东西。

我很确定我已经安装了模块。如果我跑:

代码语言:javascript
复制
ls -1 usr/local/lib/node_modules/

结果是:

代码语言:javascript
复制
express
forever
fstream
fstream-ignore
generator-keystone
http-server
keystone
node-debug
node-gyp
node-inspector
npm
yo

该命令完全适用于本地安装的模块。

添加npm config ls -l的结果,可能会有更多帮助。

代码语言:javascript
复制
; cli configs
long = true
user-agent = "npm/3.3.12 node/v4.1.2 darwin x64"

; default values
access = null
also = null
always-auth = false
bin-links = true
browser = null
ca = null
cache = "/Users/ash/.npm"
cache-lock-retries = 10
cache-lock-stale = 60000
cache-lock-wait = 10000
cache-max = null
cache-min = 10
cafile = undefined
cert = null
color = true
depth = null
description = true
dev = false
dry-run = false
editor = "vi"
engine-strict = false
fetch-retries = 2
fetch-retry-factor = 10
fetch-retry-maxtimeout = 60000
fetch-retry-mintimeout = 10000
force = false
git = "git"
git-tag-version = true
global = false
globalconfig = "/usr/local/etc/npmrc"
globalignorefile = "/usr/local/etc/npmignore"
group = 20
heading = "npm"
https-proxy = null
if-present = false
ignore-scripts = false
init-author-email = ""
init-author-name = ""
init-author-url = ""
init-license = "ISC"
init-module = "/Users/ash/.npm-init.js"
init-version = "1.0.0"
json = false
key = null
link = false
local-address = undefined
loglevel = "warn"
; long = false (overridden)
message = "%s"
node-version = "4.1.2"
npat = false
onload-script = null
only = null
optional = true
parseable = false
prefix = "/usr/local"
production = false
progress = true
proprietary-attribs = true
proxy = null
rebuild-bundle = true
registry = "https://registry.npmjs.org/"
rollback = true
save = false
save-bundle = false
save-dev = false
save-exact = false
save-optional = false
save-prefix = "^"
scope = ""
searchexclude = null
searchopts = ""
searchsort = "name"
shell = "/bin/bash"
shrinkwrap = true
sign-git-tag = false
strict-ssl = true
tag = "latest"
tag-version-prefix = "v"
tmp = "/var/folders/3r/9ljlgw6j7m53hwxm_3c3gdkw000106/T"
umask = 18
unicode = true
unsafe-perm = true
usage = false
user = 501
; user-agent = "npm/{npm-version} node/{node-version} {platform} {arch}" (overridden)
userconfig = "/Users/ash/.npmrc"
version = false
versions = false
viewer = "man"
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-13 14:53:18

所以我以一种残酷的方式解决了这个问题,但是在答案的最后,你会发现对你的机器更温和的建议。

我实际上重新安装了节点。在这样做之前,我删除了前面安装的所有内容,就像其他一些帖子中所建议的那样。

这里是上一篇文章中建议的脚本的直接链接。

至于其余部分,您应该已经知道如何安装Node了。

经验教训:始终使用nvm,并在安装/卸载-g选项之前考虑几次。

现在,npm ls -g --depth=0成为了一种魅力:

代码语言:javascript
复制
/usr/local/lib
├── generator-keystone@0.3.9
├── npm@2.14.7
└── yo@1.5.0

那时,我对配置文件的更改感到好奇。

我又跑了:npm config ls -l

它的开头类似:

代码语言:javascript
复制
; cli configs
long = true
user-agent = "npm/2.14.7 node/v4.2.2 darwin x64"

然后又出现了这些新的线条,它们是缺失的:

代码语言:javascript
复制
; globalconfig /usr/local/etc/npmrc
prefix = "/usr/local"

然后保持原样:

代码语言:javascript
复制
; default values
access = null
[..]

因此,一个更合适的答案是如下所示。

最后我还没有测试它,但是如果默认情况下安装了所有的东西,那么/usr/local/etc中就会有一个文件npmrc。为了使它指向正确的位置,您应该运行:

代码语言:javascript
复制
npm config set globalconfig /etc/npmrc

有关globalconfig的详细信息

希望大家都这么想。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33676873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档