You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 11:52:05