Firebase函数onCreate触发器错误:TypeError:无法读取属性';匹配';未定义的

Firebase函数onCreate触发器错误:TypeError:无法读取属性';匹配';未定义的,firebase,firebase-realtime-database,google-cloud-functions,Firebase,Firebase Realtime Database,Google Cloud Functions,尝试为数据库部署触发OnCreate的函数,但它不断返回此错误。下面是简单的代码和错误响应: 只是无法找出为什么匹配未定义错误 模块的版本: 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" 代码

尝试为数据库部署触发OnCreate的函数,但它不断返回此错误。下面是简单的代码和错误响应:

只是无法找出为什么匹配未定义错误

模块的版本:

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());
});
问题更新:这是最新和最新的代码。我正在尝试获取新添加对象的详细信息

错误firebase数据库中的用户添加了新元素:

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>
TypeError:无法读取未定义的属性“match”
位于resourceToInstanceAndPath(/srv/node_modules/firebase functions/lib/providers/database.js:154:26)
在dataConstructor(/srv/node_modules/firebase functions/lib/providers/database.js:122:38)
反对。(/srv/node_modules/firebase functions/lib/cloud functions.js:89:32)
在Generator.next()处
at/srv/node_modules/firebase functions/lib/cloud functions.js:28:71
在新的承诺()
at_uuwaiter(/srv/node_modules/firebase functions/lib/cloud functions.js:24:12)
在cloudFunction(/srv/node_modules/firebase functions/lib/cloud functions.js:82:36)
at/worker/worker.js:728:24
在
您正在使用云函数的“旧”语法(Firebase SDK的云函数版本1.0.0之前)和
onCreate((event)=>{})
,项目中的SDK版本为1.1.0

您应该将语法更改为

.onCreate((snap, context) => {})

正如在

中所解释的,我也有这个问题,我相信这与在firebase函数中使用node8有关。至少这是最后一次重大更改。

我遇到了这个问题,发现我的云函数触发器事件类型(write)和对
firebase.database.ref(“…”).onChange(…)
的调用不匹配。一旦我将调用切换到
firebase.database.ref(“…”).onWrite(…)
,一切都很顺利


我犯了个愚蠢的错误。希望这对其他人有帮助

我也有同样的错误,当我部署时,我有以下警告:

⚠ 函数:您必须具有位于的firebase函数版本 至少2.0.0。请运行npm i--保存firebase-functions@latest在 功能文件夹

在我安装了最后一个firebase functions版本之后,它工作了

所以我的解决方案是:

npm i——拯救火基-functions@latest


嘿@Renaud Tarnec,我确实尝试过使用,但也导致了相同的错误。您使用的是什么确切的控制台日志。你能在你的问题中添加你正在尝试的确切代码和你得到的错误吗?我有其他函数,它们似乎工作正常,但这一个似乎是个问题。每次向firebase数据库添加新值时,函数都会触发,但总是返回相同的错误。您的代码中是否还有另一部分调用了名为
匹配的属性?没有,除了这一个文件之外,没有任何内容,这正是我的原因,因为我没有做任何匹配和返回未定义的操作,所以以下操作应该有效,请参见我的回答:
exports.dbCreate=functions.database.ref('/user/{uid}/email').onCreate((snap,context)=>{const createdData=snap.val();console.log(createdData);})