Firebase 函数 onCreate 触发器错误:TypeError:无法读取未定义的属性“匹配" [英] Firebase Functions onCreate trigger Error: TypeError: Cannot read property 'match' of undefined
问题描述
尝试使用为数据库触发的 OnCreate 部署函数,但它一直向我返回此错误.这是简单的代码和错误响应:
Trying to deploy a function with OnCreate triggered for a database but it keeps returning me this error. Here's the simple code and the error response:
只是无法弄清楚为什么匹配未定义错误?
Just not able to figure out why the match undefined error?
模块版本:
nodejs: Version 8.11.3
Function : deployed with node 8 runtime version.
"firebase": "^5.3.0"
"firebase-admin": "^5.12.1"
"firebase-functions": "^1.1.0"
"typescript": "^2.5.3"
代码:
import functions = require('firebase-functions');
import admin = require('firebase-admin');
exports.functionName = functions.database.ref('/user/{uid}/email').onCreate((snap, context) => {
console.log(snap.val());
});
问题更新:这是最新和最新的代码.我正在尝试获取新添加的对象的详细信息.
Question Update: This is the latest and most updated code. I am trying to get the details of the object newly added.
Firebase 数据库中向用户添加了一个新元素时出错:
Error there is a new element added to user in firebase database:
TypeError: Cannot read property 'match' of undefined
at resourceToInstanceAndPath (/srv/node_modules/firebase-functions/lib/providers/database.js:154:26)
at dataConstructor (/srv/node_modules/firebase-functions/lib/providers/database.js:122:38)
at Object.<anonymous> (/srv/node_modules/firebase-functions/lib/cloud-functions.js:89:32)
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:728:24
at <anonymous>
推荐答案
我有同样的错误,当我部署时我有这个警告:
I had the same error, when i deployed i had this warning:
⚠ 函数:您必须有一个 firebase-functions 版本,该版本位于至少 2.0.0.请运行 npm i --save firebase-functions@latest 在函数文件夹.
⚠ functions: You must have a firebase-functions version that is at least 2.0.0. Please run npm i --save firebase-functions@latest in the functions folder.
在我安装了它工作的最后一个 firebase-functions 版本之后.
after i installed the last firebase-functions version it worked.
所以我的解决方案是:
npm i --save firebase-functions@latest
npm i --save firebase-functions@latest
这篇关于Firebase 函数 onCreate 触发器错误:TypeError:无法读取未定义的属性“匹配"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!