云函数 Firestore 触发器 - "Cannot read property 'eventType' of undefined"



我正在尝试编写一个云函数,在向usersFirestore表添加新用户时验证用户的电子邮件。(请参阅此文档。(我有以下TypeScript代码:

exports.validateEmail = functions.firestore
.document('users/{userId}')
.onCreate(async (snapshot, context) => {
const email = snapshot.get('email');
console.log(email);  // Correctly logs email
await validateEmail(email);
});
export const validateEmail = async (email: string) => {
console.log(`Validating email: ${email}.`);  // Code doesn't get to this line
// more code
};

然而,我得到了错误:

"无法读取未定义的"的属性"eventType";

这里有一个类似的问题,尽管它指的是未定义的"匹配",并且没有一个建议的解决方案对我有效/适用。

我通过在一个新的项目目录中运行firebase init,选择我的Firebase项目,选择函数,选择使用npm安装依赖项,并选择TypeScript来设置云函数。以下是我的软件包.json:的相关部分

"engines": {
"node": "10"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0",
},
"devDependencies": {
"firebase-functions-test": "^0.2.0",
"tslint": "^5.12.0",
"typescript": "^3.8.0"
}

这是我tsconfig.json的一部分:

"compilerOptions": {
"module": "commonjs",
"noImplicitReturns": true,
"noUnusedLocals": true,
"outDir": "lib",
"sourceMap": true,
"strict": true,
"target": "es2017"
}

有人知道这里未定义的是什么吗?即eventType是什么的属性,我该如何修复它?

您正在重新定义validateEmail函数。您只需为实用程序函数指定另一个名称,该名称和第一个导出的Cloud函数的名称不冲突。

相关内容

最新更新