【问题标题】:why is firebase serve throwing error but not firebase deploy?为什么 firebase 服务抛出错误而不是 firebase 部署?
【发布时间】:2019-09-04 15:13:02
【问题描述】:

我是 Firebase 的新手。我尝试连接 Firestore 和云功能(Node JS)。

我尝试运行firebase serve

但它显示了一个错误,提示无法在 gcloud 中加载默认凭据。

我已经尝试过firebase deploy,它工作得很好。只有当我在本地运行时才会显示错误。

我还需要在谷歌云中创建一个帐户并将我的应用程序链接到它吗?

这是完整的输出错误:

i  functions: Beginning execution of "getScreamDet"
>  Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
>      at GoogleAuth.getApplicationDefaultAsync (/Users/vigneshwar/Desktop/rsocialapp-backend/functions/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
>      at process._tickCallback (internal/process/next_tick.js:68:7)

【问题讨论】:

    标签: firebase google-cloud-firestore


    【解决方案1】:

    我想你正在尝试使用firebase-admin 包。 至于最新的 firebase-admin,您不能使用这样的默认凭据进行初始化。

    const admin = require('firebase-admin');
    admin.initializeApp();
    

    您需要使用 serviceAccount 凭据。转到 Firebase 项目设置 > 服务帐户 > FirebaseAdminSdk。复制代码进行初始化。

    你最终会得到类似这样的东西:

    const admin = require('firebase-admin');
    var serviceAccount = require("path/to/serviceAccountKey.json");
    admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: "xxxxx"
    });
    

    【讨论】:

      猜你喜欢
      • 2020-10-26
      • 1970-01-01
      • 2018-10-20
      • 2019-10-01
      • 1970-01-01
      • 2021-06-15
      • 2020-01-31
      • 1970-01-01
      相关资源
      最近更新 更多