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

时间:2018-09-06 18:38:58

标签: firebase debugging google-cloud-functions local

目标

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

问题

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

尝试了什么

根据Google文档here,其中的说明包括 这些步骤:

  

设置模拟功能(云以外的)的管理凭据   Firestore和实时数据库):

     
      
  1. 打开Goog​​le Cloud Console的“服务帐户”窗格。

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

  4.   
  5. 出现提示时,选择JSON   作为密钥类型,然后单击创建。将您的Google设置为默认   指向下载密钥的凭据:

         

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

         

    $ firebase functions:shell

         

    OR

         

    $ firebase serve --only functions

  6.   

完成这些说明并运行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功能,并尝试了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服务。

     

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);
  }
});

1 个答案:

答案 0 :(得分:0)

答案

文档中的内容如下:

  

如果您使用的是自定义功能配置变量,请运行   在项目的功能目录中的以下命令之前   运行Firebase服务。

     

firebase functions:config:get > .runtimeconfig.json

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