gpt4 book ai didi

Firebase 函数 onCreate 触发器错误 : TypeError: Cannot read property 'match' of undefined

转载 作者:行者123 更新时间:2023-12-02 22:08:26 25 4
gpt4 key购买 nike

尝试部署一个为数据库触发 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>

最佳答案

您使用的是 Cloud Functions 的“旧”语法(Firebase SDK for Cloud Functions 版本 1.0.0 之前的版本)以及 onCreate((event) => {}) 和版本您项目中的SDK版本为1.1.0。

您应该将语法更改为

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

documentation 中所述

关于Firebase 函数 onCreate 触发器错误 : TypeError: Cannot read property 'match' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52052200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com