使用本地模拟器 - Firebase 服务 - 错误:证书对象必须是对象



>目标

使用 Firebase模拟器并在本地部署 Firebase Cloud 函数进行测试和调试。

问题

运行firebase serve时,失败并显示 -Error: Certificate object must be an object.

尝试过什么

按照谷歌的文档,说明包括 这些步骤:

为模拟函数(云除外(设置管理员凭据 Firestore 和实时数据库(:

  1. 打开 Google Cloud Console 的"服务帐户"窗格。

  2. 确保已选择 App Engine 默认服务帐号,然后使用右侧的选项菜单选择创建密钥。

  3. 出现提示时,选择 JSON ,然后单击创建。设置您的谷歌默认值 指向已下载密钥的凭据:

    $ export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json"

    $ firebase functions:shell

    OR

    $ firebase serve --only functions

完成这些说明并运行firebase serve...失败。以下是日志:

Silver-Sliver:functions dchaddportwine$ firebase serve --only functions
=== Serving from '/Users/dchaddportwine/Sites/people-is-cloud-functions/functions'...
i  functions: Preparing to emulate functions.
Warning: You're using Node.js v8.11.1 but Google Cloud Functions only supports v6.11.5.
⚠  functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
⚠  functions: Error from emulator. Error occurred while parsing your function triggers.
Error: Certificate object must be an object.
at FirebaseAppError.FirebaseError [as constructor] (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:39:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:85:28)
at new FirebaseAppError (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/utils/error.js:119:28)
at new Certificate (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/auth/credential.js:106:19)
at new CertCredential (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/auth/credential.js:189:64)
at Object.cert (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/node_modules/firebase-admin/lib/firebase-namespace.js:220:58)
at Object.<anonymous> (/Users/dchaddportwine/Sites/people-is-cloud-functions/functions/index.js:21:32)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)

问题

如何修复这两个错误?

  1. 我安装了火力基础功能,并尝试了npm i --save firebase-functions

    ⚠ functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.

  2. 认为这与GOOGLE_APPLICATION_CREDENTIALS有关,但我不确定如何验证或检查这里发生的事情。

    ⚠ functions: Error from emulator. Error occurred while parsing your function triggers.

错误:证书对象必须是对象。

更新

在文档中,它进一步写道:

如果使用自定义函数配置变量,请运行 之前项目函数目录中的以下命令 运行火力基地发球。

firebase functions:config:get > .runtimeconfig.json

运行此命令后,我不再收到证书错误。呜呜!但是,我遇到了新的故障,并且日志中的提示并不多。

=== Serving from '/Users/dchaddportwine/Sites/people-is-cloud-functions/functions'...
i  functions: Preparing to emulate functions.
i  hosting[development-is]: Serving hosting files from: ./
✔  hosting[development-is]: Local server: http://localhost:5000
Warning: You're using Node.js v8.11.1 but Google Cloud Functions only supports v6.11.5.
⚠  functions: Failed to emulate app
⚠  functions: Failed to emulate helloSlack
⚠  functions: Failed to emulate helloIssy
⚠  functions: Failed to emulate interactiveIssy
i  functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.

法典

以下是用于helloSlack的火力云函数

exports.helloSlack = functions.https.onRequest((req, res) => {
if (req) {
res.status(200).send(req.body);
} else {
console.log("req Error...");
throw res.status(500);
}
});

答案

在文档中,它进一步写道:

如果使用自定义函数配置变量,请运行 之前项目函数目录中的以下命令 运行火力基地发球。

firebase functions:config:get > .runtimeconfig.json

此项目使用自定义函数配置变量。因此,运行config命令后,我不再收到证书错误。呜呜!

相关内容

最新更新