Using the local emulator - Firebase Serve - Error: Certificate object must be an object

Using the local emulator - Firebase Serve - Error: Certificate object must be an object

目标

使用 firebase 模拟器并在本地部署 firebase 云功能进行测试和调试。

问题

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

尝试了什么

遵循 Google 的文档 here,说明包括 这些步骤:

To set up admin credentials for emulated functions (other than Cloud Firestore and Realtime Database):

  1. Open the Service Accounts pane of the Google Cloud Console.

  2. Make sure that App Engine default service account is selected, and use the options menu at right to select Create key.

  3. When prompted, select JSON for the key type, and click Create. Set your Google default credentials to point to the downloaded key:

    $ 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. 我安装了 firebase-functions,并尝试过 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.

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

UPDATE

在文档的后面,它写道:

If you're using custom functions configuration variables, run the following command in the functions directory of your project before running firebase serve.

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

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

回答

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

If you're using custom functions configuration variables, run the following command in the functions directory of your project before running firebase serve.

firebase functions:config:get > .runtimeconfig.json

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