Google Cloud Functions v2:onValueUpdated/onValueWritten触发失败报错
TypeError: func is not a function 导致Cloud Functions v2 Realtime Database触发器失效
- 问题现象:部署v2版本Google Cloud Function,配置
onValueUpdated触发器监听Realtime Database的/cache/ganttJson/trigger节点,更新节点时函数未运行,抛出TypeError: func is not a function错误。经测试,onValueWritten触发器存在同样问题,仅onValueCreated可正常触发。 - 环境信息:firebase-tools 13.7.4、Node.js v20.12.2
- 问题根源:
cache.js文件中调用onValueUpdated时存在语法错误——多添加了一对括号,导致返回值并非预期的函数类型,触发报错。 - 修正方案:
错误写法(多余括号导致返回值异常):
正确写法:// 错误示例:多写了括号,导致返回值不是函数 onValueUpdated({ref: "/cache/ganttJson/trigger", region: "europe-west1"})(async (event) => { /* 回调逻辑 */ })onValueUpdated({ref: "/cache/ganttJson/trigger", region: "europe-west1"}, async (event) => { /* 回调逻辑 */ })
内容的提问来源于stack exchange,提问作者Kermit
相关产品推荐
相关产品推荐

