首页 > 解决方案 > 仅本地主机上的 Firebase 托管保留 URL“/__/firebase/init.js”中缺少应用配置 appId

问题描述

我最近开始在 Chrome 中的 Firebase 托管网站的 localhost 版本上看到一个错误:

Uncaught FirebaseError: Installations: Missing App configuration value: "appId" (installations/missing-app-config-values).

我不确定是什么触发了这个。我正在使用 Firebase Hosting Reserved URL 方法来包含 firebase 配置,直到最近才出现问题。

配置是通过<script src="/__/firebase/init.js"></script>.

这是该 URL 的配置文件:

if (typeof firebase === 'undefined') throw new Error('hosting/init-error: Firebase SDK not detected. You must include it before /__/firebase/init.js');
var firebaseConfig = {
  "projectId": "remotesoc...",
  "databaseURL": "https://remotesoc...firebaseio.com",
  "storageBucket": "remotesoc...appspot.com",
  "locationId": "us-central",
  "apiKey": "AIzaSyC3K7HT9- ... ",
  "authDomain": "remotesoc...firebaseapp.com",
  "messagingSenderId": "43697..."
};
if (firebaseConfig) {
  firebase.initializeApp(firebaseConfig);
}

如您所见,缺少“appId”值。我几乎可以肯定这曾经在那里。

我已多次构建和部署该应用程序,这被列为确保 Firebase 具有项目的正确配置值的方式。

该应用程序肯定使用了正确的项目,并且在 firebase.json 中引用了托管站点

{
  "database": {
    "rules": "database.rules.json"
  },
  "functions": {
    "source": "functions"
  },
  "hosting": {
    "site": "remotesoc...",
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  }
}

我曾>firebase init多次尝试重置 CLI。

部署的站点没有丢失的配置变量,并且运行良好,这仅在 localhost 上。

我可以恢复使用包含的配置文件,但这否定了保留 URL 为您注入值的好处。

任何帮助,将不胜感激。

标签: reactjsfirebasefirebase-hostingfirebase-tools

解决方案


推荐阅读