我正在使用 Homebrew 在干净的 macOS Mojave 机器上安装节点。我正在尝试在用户拥有的目录中设置 npm 安装目录;该目录tools
已存在并归用户所有:
npm config set prefix '/Users/giorgio/tools/npm_global'
这条消息失败了。有谁知道发生了什么事?
Error: EACCES: permission denied, mkdir '/tools'
TypeError: Cannot read property 'loaded' of undefined
at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27)
at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
at /usr/local/lib/node_modules/npm/bin/npm-cli.js:78:20
at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22)
at /usr/local/lib/node_modules/npm/lib/npm.js:263:24
at /usr/local/lib/node_modules/npm/lib/config/core.js:83:7
at Array.forEach (<anonymous>)
at /usr/local/lib/node_modules/npm/lib/config/core.js:82:13
at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:173:20)
/usr/local/lib/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 (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:98:27)
at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
at process.emit (events.js:197:13)
at process._fatalException (internal/process/execution.js:123:25)
非常随机地找到了解决方案。好像我第一次尝试时
set prefix
确实使用了错误的路径字符串。我不得不手动删除.npmrc
文件并重试set prefix
命令以使其工作。我真的希望
set prefix
能够修改自己创建的 npn 配置文件。