【问题标题】:Firebase Error: Unexpected error while deploying database rulesFirebase 错误:部署数据库规则时出现意外错误
【发布时间】:2020-07-06 23:47:49
【问题描述】:

我正在尝试将我的 Angular 应用程序部署到 Firebase,我已经尝试了所有方法来初始化 Firebase,选择托管,然后从各种教程中将我的应用程序部署到 Firebase 上。但我总是得到一个错误:

我不知道怎么了。

这就是我的 firebase-debug.log 的样子

[debug] [2020-03-26T10:42:00.096Z] ----------------------------------------------------------------------
[debug] [2020-03-26T10:42:00.098Z] Command:       C:\Program Files\nodejs\node.exe C:\Users\pulki\AppData\Roaming\npm\node_modules\firebase-tools\lib\bin\firebase.js deploy
[debug] [2020-03-26T10:42:00.098Z] CLI Version:   7.16.1
[debug] [2020-03-26T10:42:00.098Z] Platform:      win32
[debug] [2020-03-26T10:42:00.098Z] Node Version:  v10.16.3
[debug] [2020-03-26T10:42:00.099Z] Time:          Thu Mar 26 2020 16:12:00 GMT+0530 (India Standard Time)
[debug] [2020-03-26T10:42:00.099Z] ----------------------------------------------------------------------
[debug] [2020-03-26T10:42:00.099Z] 
[debug] [2020-03-26T10:42:00.105Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[debug] [2020-03-26T10:42:00.105Z] > authorizing via signed-in user
[debug] [2020-03-26T10:42:00.105Z] [iam] checking project frezzo-pul5 for permissions ["firebase.projects.get","firebasedatabase.instances.update","firebasehosting.sites.update"]
[debug] [2020-03-26T10:42:00.108Z] > refreshing access token with scopes: ["email","https://www.googleapis.com/auth/cloud-platform","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","openid"]
[debug] [2020-03-26T10:42:00.108Z] >>> HTTP REQUEST POST https://www.googleapis.com/oauth2/v3/token  
 <request body omitted>
[debug] [2020-03-26T10:42:00.624Z] <<< HTTP RESPONSE 200
[debug] [2020-03-26T10:42:00.630Z] >>> HTTP REQUEST POST https://cloudresourcemanager.googleapis.com/v1/projects/frezzo-pul5:testIamPermissions  

[debug] [2020-03-26T10:42:02.770Z] <<< HTTP RESPONSE 200
[debug] [2020-03-26T10:42:02.772Z] >>> HTTP REQUEST GET https://firebase.googleapis.com/v1beta1/projects/frezzo-pul5  

[debug] [2020-03-26T10:42:03.760Z] <<< HTTP RESPONSE 200
[info] 
[info] === Deploying to 'frezzo-pul5'...
[info] 
[info] i  deploying database, hosting
[info] i  database: checking rules syntax...
[debug] [2020-03-26T10:42:03.764Z] >>> HTTP REQUEST PUT https://frezzo-pul5.firebaseio.com/.settings/rules.json?dryRun=true  
 {
    "rules": {
        ".read": true,
        ".write": true
    }
}
[debug] [2020-03-26T10:42:06.330Z] <<< HTTP RESPONSE 404
[debug] [2020-03-26T10:42:06.330Z] <<< HTTP RESPONSE BODY {
  "error" : "Firebase error. Please ensure that you spelled the name of your Firebase correctly"
}

[error] 
[error] Error: Unexpected error while deploying database rules.

我没有在我的 firebase 数据库上设置任何安全性。这是个问题吗?

我还尝试使用 firebase serve 在本地检查我的应用,效果很好。

谢谢你的帮助!!

【问题讨论】:

  • 此错误通常意味着您的数据库名称中有拼写错误。您确定 frezzo-pul5 是您项目的确切名称吗?
  • 是的,我刚刚检查了 firebase 控制台上的项目名称是否不同,但是在将数据读取和写入数据库时​​,它不会给出任何错误。知道我现在应该如何修复它
  • 您可能需要重新初始化您的 Firebase CLI 正在使用的 Firebase 项目。要么在一个空目录中重新运行firebase initialize,然后完成移动文件,要么使用firebase alias 修复当前目录。另见firebase.google.com/docs/cli#project_aliases
  • 我之前使用过 frezzo-pul5,但后来我从 firebase 中删除了该项目并创建了一个新项目 ID - frezzo-cdefe,它在读取和写入数据时工作得很好,但我不知道为什么我无法从仍然显示 frezzo-pul5 的 cli 更改它
  • 对旧项目的引用可能在.firebaserc 文件中,这是您可以使用firebase alias 管理的。如果这不起作用,只需删除文件并重新初始化即可。

标签: firebase firebase-realtime-database firebase-security firebase-cli


【解决方案1】:

尝试从控制台启动 firebase 数据库。在大多数情况下,firebase 数据库未设置在云上,因此控制台实用程序无法上传 db 规则,因此会出现此错误。尝试使用以下命令:

firebase init database

以下更新将在控制台上进行:

=== Database Setup
i  database: ensuring required API firebasedatabase.googleapis.com is enabled...
⚠  database: missing required API firebasedatabase.googleapis.com. Enabling now...
✔  database: required API firebasedatabase.googleapis.com is enabled

? It seems like you haven’t initialized Realtime Database in your project yet. Do you want to set it up? Yes
? Please choose the location for your default Realtime Database instance: us-central1
✔ Creating your default Realtime Database instance: ********-default-rtdb

这样,您的数据库部署错误可能会得到解决。

【讨论】:

    【解决方案2】:

    如果您在激活后停用了一项或多项功能,则在运行时 第一次$ firebase init,部署的时候会搞砸的。

    例如,有时如果您不使用实时数据库,它们会自动停用,只需尝试重新启用它们以便能够部署即可。否则,您需要使用不同的选项重新运行 init,并删除未使用的文件以使其正常工作。

    【讨论】:

      猜你喜欢
      • 2019-09-11
      • 2019-09-30
      • 1970-01-01
      • 1970-01-01
      • 2020-11-30
      • 2020-11-08
      • 1970-01-01
      • 2022-01-09
      • 2023-03-04
      相关资源
      最近更新 更多