(firebase-admin) Error: Error: Client is offline but its not?

(firebase-admin) Error: Error: Client is offline but its not?

import * as admin from "firebase-admin";
import DataModel from "../types/firebase";

export class FirebaseManager {
  db = admin.database();

  constructor() {
    this.db = admin.database();
    if (this.db === undefined) {
      throw "cannot find database";
    }

    let data = this.db
      .ref(`/`)
      .get()
      .then((snapshot) => {
        if (!snapshot.exists()) {
          throw "no database found :(";
        } else {
          let data = snapshot.val();
          try {
            let castedData = data as DataModel;
            console.log("Database successfully initialised!");
          } catch {
            throw "Data could not be casted properly during initialisation";
          }
        }
      });
  }
}

嗨,我一直在开发一个需要 firebase 作为后端的 discord 机器人。但是,当我初始化此 class 时,调用 .get() 函数显示 Error: Error: Client is offline 但我一直在线,有人知道为什么吗?作为参考,我使用的是特定版本 "firebase-admin": "^9.11.1"。如果您想查看所有代码,https://github.com/MaxiGames/MaxiGames.js/tree/firebase 就在这里。

糟糕,问题是我们需要按照这里的教程 https://firebase.google.com/docs/admin/setup 并设置一个环境变量,然后使用 admin.credential.applicationDefault() 作为我们输入到 initialiseApp 函数中的对象的凭据参数.所以,最后代码应该看起来像 admin.initializeApp({credential:admin.credential.applicationDefault(), databaseURL:"https://{your-project}-default-rtdb.firebaseio.com"});