遇到与Cloud Function Triggers和Firestore相关的错误

时间:2018-12-05 23:01:01

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

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

代码:

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)

版本:

“ firebase”:“ ^ 5.3.0”

“ firebase-admin”:“ ^ 5.12.1”

“ firebase-functions”:“ ^ 1.1.0”

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

1 个答案:

答案 0 :(得分:1)

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