如何解决导致我无法全局下载Firebase的权限问题? | Node.js

发布时间:2020-07-07 12:06

我正在尝试设置Firebase托管。

当我使用以下命令时:npm install -g firebase-tools

失败,该错误似乎是权限错误。我尝试遵循有关如何修复权限错误的指南,但无法使其正常工作。

您能带我逐步解决此问题吗?这将非常有帮助。

这是错误日志:

v12.15.0
Andrews-iMac:My Website andrewtillott$ npm install -g firebase-tools
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR!   stack: "Error: EACCES: permission denied, access '/usr/local/lib/node_modules'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/andrewtillott/.npm/_logs/2020-07-07T12_01_34_017Z-debug.log
Andrews-iMac:My Website andrewtillott$ 

更新

我尝试再次手动更改npm的默认目录。

这可能已经解决了这个问题,如果解决了,我很想知道它是如何工作的,以及我在这里实际上做了什么:

Andrews-iMac:My Website andrewtillott$ mkdir ~/.npm-global
mkdir: /Users/andrewtillott/.npm-global: File exists
Andrews-iMac:My Website andrewtillott$ npm config set prefix '~/.npm-global'
Andrews-iMac:My Website andrewtillott$ export PATH=~/.npm-global/bin:$PATH
Andrews-iMac:My Website andrewtillott$ source ~/.profile
bash: /Users/andrewtillott/.profile: No such file or directory
Andrews-iMac:My Website andrewtillott$ npm install -g firebase-tools
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
/Users/andrewtillott/.npm-global/bin/firebase -> /Users/andrewtillott/.npm-global/lib/node_modules/firebase-tools/lib/bin/firebase.js

> protobufjs@6.9.0 postinstall /Users/andrewtillott/.npm-global/lib/node_modules/firebase-tools/node_modules/protobufjs
> node scripts/postinstall

+ firebase-tools@8.4.3
added 531 packages from 358 contributors in 41.687s
Andrews-iMac:My Website andrewtillott$ 
回答1