gpt4 book ai didi

javascript - 类型错误 : Cannot read property 'match' of undefined when calling Firebase Cloud Function

转载 作者:行者123 更新时间:2023-12-01 00:41:08 25 4
gpt4 key购买 nike

我在 index.js 文件中定义了一个云函数,如下所示:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.newMessage = functions.database
.ref('/privateMessages/{userA}/{userB}/{message}')
.onWrite((snap, context) => {
const original = snap.after.val();
const userA = context.params.userA;
const userB = context.params.userB;
const message = context.params.message;
console.log('debug', userA, userB, original, message);
return ;
});

当函数执行开始时,我总是收到以下错误:

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:825:24
at <anonymous>

Firebase实时数据库的结构如下所示。如果现有的userA和userB之间有任何新的消息创建,则会创建一个新的消息条目。如果是新的聊天 session ,则会创建新的 userA 和 newB 以及消息。 enter image description here

functions文件夹中的package.json如下:

{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase serve --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~5.12.0",
"firebase-functions": "^1.0.1"
},
"devDependencies": {
"eslint": "^4.12.0",
"eslint-plugin-promise": "^3.6.0"
},
"private": true,
"engines": {
"node": "8"
}
}

最佳答案

您正在使用一个非常旧的 firebase-functions 模块。最新的是3.2.0。你可以看到有same bug不久前报告过,但该问题已被关闭。

(您的 firebase-admin 也很旧了。)

关于javascript - 类型错误 : Cannot read property 'match' of undefined when calling Firebase Cloud Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57702876/

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