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

Firebase Cloud Functions Pub/Sub调度部署报错:functions.pubsub.schedule不是函数

解决Firebase Cloud Functions定时函数部署错误:TypeError: functions.pubsub.schedule is not a function

我之前也踩过一模一样的坑!你遇到的问题核心其实很容易被忽略——只更新了Firebase CLI部署工具,但没升级项目本地的firebase-functions依赖包,schedule这个定时任务方法是firebase-functions v2.2.0及以上版本才新增的功能,和Firebase CLI版本没有直接关联。

具体解决方案步骤:

  1. 切换到你的Cloud Functions项目目录(就是包含package.json的functions文件夹)
  2. 先检查当前firebase-functions的版本:
    npm list firebase-functions
    
  3. 如果版本低于v2.2.0,执行升级命令:
    npm install firebase-functions@latest --save
    
  4. 顺带把firebase-admin也更新到最新版本,避免出现兼容性问题:
    npm install firebase-admin@latest --save
    
  5. 最后重新部署函数:
    firebase deploy --only functions
    

补充说明:

你提供的代码本身是完全正确的:

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

exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
  console.log('This will be run every 5 minutes!');
});

很多人会误以为更新Firebase CLI就足够,但CLI只是负责部署的工具,函数运行时依赖的是你项目本地安装的npm包版本,两者是相互独立的,这也是这个问题最容易踩坑的地方。

内容的提问来源于stack exchange,提问作者Sss Steve

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 05:06:32