【问题标题】:Where is NPM config file?NPM 配置文件在哪里?
【发布时间】:2021-08-18 00:09:17
【问题描述】:

我使用npm edit config 编辑了 npm 配置文件。我在其中犯了语法错误并保存了文件。现在,无论我用 npm 尝试什么,它都会抱怨它。我知道语法是什么,我想修复它,但我无法在任何地方找到该文件。

C:\Users\Arthur>npm
Error: Failed parsing JSON config key cache: "C:\Users\Le Roi Arthur\AppData\Roaming\npm-cache"
    at parseField (D:\nodejs\node_modules\npm\lib\config\core.js:376:13)
    at D:\nodejs\node_modules\npm\lib\config\core.js:330:24
    at Array.forEach (<anonymous>)
    at Conf.add (D:\nodejs\node_modules\npm\lib\config\core.js:328:23)
    at ConfigChain.addString (D:\nodejs\node_modules\npm\node_modules\config-chain\index.js:244:8)
    at Conf.<anonymous> (D:\nodejs\node_modules\npm\lib\config\core.js:316:10)
    at D:\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:90:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
TypeError: Cannot read property 'loaded' of undefined
    at exit (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
    at errorHandler (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at D:\nodejs\node_modules\npm\bin\npm-cli.js:77:20
    at cb (D:\nodejs\node_modules\npm\lib\npm.js:225:22)
    at D:\nodejs\node_modules\npm\lib\npm.js:263:24
    at D:\nodejs\node_modules\npm\lib\config\core.js:83:7
    at Array.forEach (<anonymous>)
    at Conf.<anonymous> (D:\nodejs\node_modules\npm\lib\config\core.js:82:13)
    at Conf.f (D:\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
    at Object.onceWrapper (events.js:286:20)
D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
    at process.errorHandler (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at process.emit (events.js:198:13)
    at process._fatalException (internal/bootstrap/node.js:496:27)
Error: Failed parsing JSON config key cache: "C:\Users\Le Roi Arthur\AppData\Roaming\npm-cache"
    at parseField (D:\nodejs\node_modules\npm\lib\config\core.js:376:13)
    at D:\nodejs\node_modules\npm\lib\config\core.js:330:24
    at Array.forEach (<anonymous>)
    at Conf.add (D:\nodejs\node_modules\npm\lib\config\core.js:328:23)
    at ConfigChain.addString (D:\nodejs\node_modules\npm\node_modules\config-chain\index.js:244:8)
    at Conf.<anonymous> (D:\nodejs\node_modules\npm\lib\config\core.js:316:10)
    at D:\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:90:16
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)
TypeError: Cannot read property 'loaded' of undefined
    at exit (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
    at errorHandler (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at D:\nodejs\node_modules\npm\bin\npm-cli.js:77:20
    at cb (D:\nodejs\node_modules\npm\lib\npm.js:225:22)
    at D:\nodejs\node_modules\npm\lib\npm.js:263:24
    at D:\nodejs\node_modules\npm\lib\config\core.js:83:7
    at Array.forEach (<anonymous>)
    at Conf.<anonymous> (D:\nodejs\node_modules\npm\lib\config\core.js:82:13)
    at Conf.f (D:\nodejs\node_modules\npm\node_modules\once\once.js:25:25)
    at Object.onceWrapper (events.js:286:20)
D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:98:27)
    at process.errorHandler (D:\nodejs\node_modules\npm\lib\utils\error-handler.js:216:3)
    at process.emit (events.js:198:13)
    at process._fatalException (internal/bootstrap/node.js:496:27)

卸载并重新安装 nodeJS 并不能解决问题,该文件存储在某处的缓存中。把我的手放在那个文件上是多么的困难,真是令人沮丧。

在哪里可以找到 npm 配置文件?

【问题讨论】:

  • npm 缓存清理 -f 不起作用?
  • 任何东西使用 npm 都会因为这个语法错误而失败。
  • 此解决方案使用npm 重置文件。我刚刚告诉过你这行不通。

标签: npm


【解决方案1】:

你需要编辑npmrc文件,看看documentation它会帮你找到合适的。

四个相关文件是:

  • 每个项目的配置文件:/path/to/my/project/.npmrc
  • 每用户配置文件:~/.npmrc
  • 全局配置文件:$PREFIX/npmrc
  • 内置 npm 配置文件:/path/to/npm/npmrc

【讨论】:

  • 感谢您的提示!就我而言,在 Windows 下,该文件位于 C:\Users\{USERNAME}\AppData\Roaming\npm\etc\npmrc 下。
【解决方案2】:

您可以使用以下命令查看配置文件(和其他)路径

npm config list

【讨论】:

  • 如原帖所述,任何使用npm的命令都会因为这个语法错误而失败,所以npm config list不是一个有效的解决方案。
  • 哎呀,我的错...我的谷歌搜索 npm 配置文件路径由于某种原因带来了这个页面(我猜是因为问题标题)。把它留在这里,以防有人觉得这很有趣
猜你喜欢
  • 2019-07-01
  • 2017-10-19
  • 2015-05-25
  • 1970-01-01
  • 2017-11-19
  • 2012-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多