在编写创建用户时触发的简单示例函数时出现以下错误。
代码:
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函数":"^1.1.0">
只是找不到此代码有什么问题。当一个用户文档是新创建的,我不断得到这个关于事件的错误。以前有人面对过吗?我该如何解决?
您的Firebase依赖关系看起来非常旧。firebase管理现在是6.3.0,firebase功能是2.1.0。确保您的代码为您真正想要使用的这些库的版本使用了正确的API。