【发布时间】:2016-11-16 15:08:34
【问题描述】:
默认情况下,NPM 将用户配置存储在 ~/.npmrc 中。我的用户配置中有很多东西,我不想干扰我的主项目,但我正在切换到需要不同配置的第二个项目,所以我就这样做了:
npm config set userconfig C:\path\to\another\directory\.npmrc。
令我惊讶的是,NPM 在~/.npmrc 的现有用户 配置中添加了一个新条目userconfig。这对我来说没有意义 - 似乎 NPM 需要知道用户配置在哪里才能找出它在哪里!
现在 NPM 会忽略我放入新 NPMRC 文件中的任何属性,并且只获取来自 ~/.npmrc 的属性。更奇怪的是,npm config list 包含一个 userconfig 标头(以分号为前缀的行)指定我的新位置,但内容来自~/.npmrc。
例如,如果我在~/.npmrc 中将我的电子邮件设置为“foo@example.com”,在我的新 NPMRC 中设置为“bar@example.com”,npm config list 会报告如下内容:
; cli configs
user-agent = "npm/3.10.8 node/v6.9.1 win32 x64"
; userconfig C:\path\to\another\directory\.npmrc
(... other properties ...)
email = "foo@example.com"
(... other properties ...)
userconfig = "C:\path\to\another\directory\.npmrc"
; builtin config undefined
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\
; HOME = C:\Users\MyUsername
; "npm config ls -l" to show all defaults.
该值来自~/.npmrc,尽管出现了(我仔细检查了新 NPMRC 中的值肯定是“bar@example.com”)。
我认为这可能是 NPM 中的一个错误,所以我将我的 Node/NPM 升级到了最新版本,但它的行为仍然相同。我是否使用了userconfig 错误,它应该如何工作?
【问题讨论】:
-
这玩意已经在后面咬了mi。根据文档(docs.npmjs.com/files/npmrc#per-user-config-file),它假设指向您由 userconfig 选项描述的其他 .npmrc,但它没有这样做。然而,最令人讨厌的是它一开始似乎工作的事实。我使用 npm config set 设置了 userconfig,并且 npm config list 开始列出另一个文件中的选项。但是,一旦我关闭终端,它就会停止工作,并且我无法重现它,因为:(
标签: node.js configuration npm