为什么全球安装的npm模块无法列出?

时间:2015-11-12 16:49:20

标签: node.js terminal npm

我正在跑步:

npm ls -g 

它没有显示任何内容。

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

ls -1 usr/local/lib/node_modules/

结果是:

express
forever
fstream
fstream-ignore
generator-keystone
http-server
keystone
node-debug
node-gyp
node-inspector
npm
yo

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

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

; 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"

1 个答案:

答案 0 :(得分:0)

所以我以残酷的方式解决了这个问题,但在答案结束时,你会发现建议让你的机器更加温和。

我实际上重新安装了节点。在此之前,我删除了之前安装的所有内容,如其他一些post中建议的那样。

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

对于其他人,您应该已经知道如何安装Node。

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

现在npm ls -g --depth=0充当魅力:

/usr/local/lib
├── generator-keystone@0.3.9
├── npm@2.14.7
└── yo@1.5.0

然后我对改变配置文件感到好奇。

我又跑了:npm config ls -l

它开始相似:

; cli configs
long = true
user-agent = "npm/2.14.7 node/v4.2.2 darwin x64"

然后是这些缺失的新行:

; globalconfig /usr/local/etc/npmrc
prefix = "/usr/local"

然后保持不变:

; default values
access = null
[..]

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

我最后没有对它进行过测试,但是如果你默认安装了所有东西,那么/ usr / local / etc中的文件是npmrc。要使其指向正确的位置,您应该运行:

npm config set globalconfig /etc/npmrc

有关globalconfig

的详细信息

希望是所有人。