【问题标题】:Why npm modules installed globally can't be listed?为什么无法列出全局安装的 npm 模块?
【发布时间】:2015-11-12 16:49:20
【问题描述】:

我在跑步:

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"

【问题讨论】:

  • 如果您安装带有-g 标志的软件包,它是否位于您的/usr/local/lib/node_modules/ 目录中?还是安装在别处?
  • 是的。我刚刚安装了 socket.io 来尝试弄清楚,它已被放置在该文件夹中。
  • npm ls -g 应该可以正常工作。它看起来像一些环境问题的配置。
  • 我在某处读到了 prefix = "/usr/local" 中的一些错误指示,应该设置为 usr/local/lib/node_modules/,但我找不到指定它的文件。它应该是一个 .npmrc 文件。
  • 好的。无需定位该文件,因为无论如何都可以更改前缀为:npm config set prefix /usr/local/ -g,但实际上没有任何变化,仍然没有显示任何模块。

标签: node.js terminal npm


【解决方案1】:

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

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

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

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

经验教训:始终使用 nvm 并在使用 -g 选项安装/卸载之前三思而后行。

现在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

希望这就是所有人。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-31
    • 2015-02-07
    • 2012-09-17
    • 2020-10-23
    • 2015-03-25
    • 1970-01-01
    • 2011-08-14
    • 2013-09-26
    相关资源
    最近更新 更多