Firebase工具错误:EACCES:权限被拒绝。

13
我正在尝试部署我的 Web 应用的 Firebase Hosting。
在命令行中,当我输入 "firebase deploy" 时,会出现以下错误。
注意: "firebase deploy" 只是一个例子。所有 firebase 命令都会出现相同的错误。 (例如 firebase --help、firebase -v、firebase login、firebase logout 等)
/usr/local/lib/node_modules/firebase-tools/node_modules/configstore/index.js:53 throw err; ^ Error: EACCES: permission denied, open '/Users/mowzer/.config/configstore/update-notifier-firebase-tools.json' You don't have access to this file. at Error (native) at Object.fs.openSync (fs.js:549:18) at Object.fs.readFileSync (fs.js:397:15) at Object.create.all.get (/usr/local/lib/node_modules/firebase-tools/node_modules/configstore/index.js:34:26) at Object.Configstore (/usr/local/lib/node_modules/firebase-tools/node_modules/configstore/index.js:27:44) at new UpdateNotifier (/usr/local/lib/node_modules/firebase-tools/node_modules/update-notifier/index.js:34:17) at module.exports (/usr/local/lib/node_modules/firebase-tools/node_modules/update-notifier/index.js:123:23) at Object. (/usr/local/lib/node_modules/firebase-tools/bin/firebase:5:48) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10)
到目前为止,我尝试了所有可能的方法(包括所有 CLI firebase 指令),但由于权限不足而无法进行操作。
我该怎么做?我应该尝试什么?
(我使用的是 Mac OS X Yosemite v10.10.5 和 firebase-tools v3.0.3)
编辑:当我输入 "sudo firebase deploy" 时,会出现以下错误。
Error: The entered credentials were incorrect.
我尝试了以下解决方案。
我尝试删除有问题的文件,然后重新安装 firebase-tools。
cd
cd .config/configstore
# Delete problematic files
rm firebase-tools.json
override rw-------  root/staff for firebase-tools.json? y
rm update-notifier-firebase-tools.json
override rw-------  root/staff for update-notifier-firebase-tools.json? y
# Reinstall firebase-tools
cd
sudo npm install -g firebase-tools

然后...
cd path/to/directory
cd firebase deploy

现在这个文件产生了错误:

/usr/local/lib/node_modules/firebase-tools/node_modules/configstore/index.js:53

cd /usr/local/lib/node_modules/firebase-tools/node_modules/configstore

请注意,本文不包含解释和修改。

2
很平凡,但是...你尝试使用sudo了吗? - Devid Farinelli
@DevidFarinelli:是的。当我执行 sudo firebase deploy 时,我会收到以下错误提示:错误:输入的凭据不正确。 - Let Me Tink About It
12个回答

35

我通过在命令行的开头添加 sudo 来解决了它的问题!


2
因为仅仅在出现问题时使用sudo不仅是低效的,而且对许多系统也是危险的,所以被踩了。修复错误设置的权限将真正解决OP的问题。 - j.Doe

20

这看起来像是您已安装的npm模块权限问题。这是许多开发者遇到的问题,实际上npm有一些文档介绍如何解决它。通过这些步骤后,再次尝试(可能需要重新安装firebase-tools),然后事情应该就会正常工作。


2
执行 "sudo npm install -g firebase-tools" 可以解决这个问题(对我而言)。 - devDeejay
使用“sudo”并不能解决任何问题。它只会将npm作为root执行,这绝对不是一种解决方法。许多项目因为以root身份执行npm而出现了故障。真正的解决方案是修复权限问题。 - j.Doe

10

我遇到了同样的问题,然后通过使用这个命令来解决它:curl -sL firebase.tools | upgrade=true bash


我尝试了这个,对我有效。 - Miguel Peguero
请将此设为采纳答案。非常好用。 - Lakindu Hewawasam
就像魔法一样奏效。 - Caleb C. Adainoo
你救了我的一天,谢谢 :) - undefined

5

在命令前添加sudo,它应该就可以正常工作了。

sudo npm -g i firebase-tools

2

我曾遇到相同的问题,通过对configstore目录下的所有文件执行chmod 755命令,问题得以解决。


1
您可以尝试使用--unsafe-perm标志。像这样:

sudo npm install -g firebase-tools --unsafe-perm

1

对@jacobawenger提供的解决方案进行更详细的扩展:

最健壮的解决方案是安装Homebrew,并让Homebrew为您管理npm包安装

# EACCESS error reference: https://docs.npmjs.com/getting-started/fixing-npm-permissions
# Install Homebrew # Reference: brew.sh # Ensures NPM is installed properly to avoid EACCESS errors
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Install npm # Reference: brew.sh
brew install node
# Install firebase-tools
npm install -g firebase-tools # Non-recurring task # Also updates to newest version (see notice)

1

简单方法:

备份你的电脑。

如果你有权限问题,先运行以下命令:

 sudo chown -R $USER /usr/local/lib/node_modules

然后第二个

1)-  mkdir ~/.npm-global
2)-  npm config set prefix '~/.npm-global'
3)-  export PATH=~/.npm-global/bin:$PATH
4)-  source ~/.profile
5)-  npm install -g jshint
6)-  NPM_CONFIG_PREFIX=~/.npm-global

0

尝试运行以下命令:

su root

如果您使用的是Ubuntu系统。 对于我来说,只使用sudo无法正常工作。 我正在使用Ubuntu 18.x.x,并尝试通过npm安装firebase。


0

对我有效的方法基本上是使用 Node 版本管理器重新安装 Node。为此,您只需以这种方式安装最新的 Node.js 版本

在我回复时的情况下,Node JS 的 LTS 版本是 v14.17.0,因此nvm use 14.17.0现在尝试重新运行构建。


谢谢您的纠正,My Yash。对于我的简写表示歉意。 - Jay R

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接