我正在使用 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)
答案1
随机找到了一个解决方案。似乎我第一次尝试时set prefix
使用了错误的路径字符串。我不得不手动删除该.npmrc
文件并重试set prefix
命令才能使其正常工作。
我确实希望set prefix
能够修改其自身创建的 npn 配置文件。