【问题标题】:Getting an error related to Cloud Function Triggers and Firestore收到与 Cloud Function Triggers 和 Firestore 相关的错误
【发布时间】:2019-05-07 14:24:52
【问题描述】:

编写一个在创建用户时触发的简单示例函数时出现以下错误。

代码:

exports.createUser = functions.firestore
  .document('users/{userId}')
  .onCreate((snap, context) => {
    const newValue = snap.data();
    const name = newValue.name;
    //....do some stuff here
  });

错误说明:

Error: Cloud function needs to be called with an event parameter.If you are writing unit tests, please use the Node module firebase-functions-fake.
    at Object.<anonymous> (/srv/node_modules/firebase-functions/lib/cloud-functions.js:84:19)
    at Generator.next (<anonymous>)
    at /srv/node_modules/firebase-functions/lib/cloud-functions.js:28:71
    at new Promise (<anonymous>)
    at __awaiter (/srv/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
    at cloudFunction (/srv/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
    at /worker/worker.js:766:24
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:228:7)

版本:

“火力基地”:“^5.3.0”

"firebase-admin": "^5.12.1"

“firebase-functions”:“^1.1.0”

只是找不到这段代码有什么问题。新创建用户文档时,我不断收到有关事件的错误。有没有人遇到过这个问题,我该如何解决?

【问题讨论】:

    标签: node.js google-cloud-firestore google-cloud-functions


    【解决方案1】:

    您的 Firebase 依赖项看起来很旧。 firebase-admin 现在是 6.3.0,而 firebase-functions 是 2.1.0。确保您的代码为您真正想要使用的这些库的版本使用正确的 API。

    【讨论】:

    • 感谢 Doug,将 firebase-admin 和 firebase-functions 更新到各自的最新版本。工作正常,我把版本控制搞砸了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-15
    • 2018-06-06
    • 2019-01-16
    • 2020-09-10
    • 2019-05-26
    • 2013-10-22
    • 2018-03-22
    相关资源
    最近更新 更多