目标
使用firebase仿真器并在本地部署firebase Cloud 功能以进行测试和调试 .
问题
当 firebase serve
运行时,它失败并显示 - Error: Certificate object must be an object.
已尝试过什么
按照Google的文档here,说明包括以下步骤:
要为模拟功能( Cloud Firestore和实时数据库除外)设置管理员凭据,请执行以下操作:打开Google Cloud Console的“服务帐户”面板 . 确保选择了App Engine默认服务帐户,并使用右侧的选项菜单选择创建密钥 . 出现提示时,为密钥类型选择JSON,然后单击“创建” . 将您的Google默认凭据设置为指向下载的密钥:$ 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)
问题
我该如何解决这两个错误?
- 我安装了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.
- 认为这与
GOOGLE_APPLICATION_CREDENTIALS
有关,但我在这里发生了_618168 .
⚠ functions: Error from emulator. Error occurred while parsing your function triggers.
错误:证书对象必须是对象 .
更新
在文档中,它的内容如下:
如果您正在使用自定义函数配置变量,请在运行firebase serve之前在项目的functions目录中运行以下命令 . firebase函数: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 Cloud 功能
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 回答
答案
在文档中,它的内容如下:
这个项目正在使用 custom functions configuration variables . 因此,在运行config命令后,我不再收到证书错误 . 活泉!