gpt4 book ai didi

node.js - 为什么无法列出全局安装的 npm 模块?

转载 作者:太空宇宙 更新时间:2023-11-04 02:20:27 25 4
gpt4 key购买 nike

我正在运行:

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"

最佳答案

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

我实际上重新安装了 Node 。在执行此操作之前,我按照其他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的详细信息

希望大家都是这样。

关于node.js - 为什么无法列出全局安装的 npm 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33676873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com