Firebase定时函数未成功部署问题求助
问题:Firebase定时函数部署后无法找到
严格遵循Firebase官方教程部署定时函数,但部署后找不到该函数。需求是让函数在指定时间触发,测试时设置为部署时间后几分钟,已启用所需GCP服务:App Engine App和PubSub。
环境信息
Functions目录结构
$ tree functions -L 1 functions ├── firestore-debug.log ├── index.js ├── node_modules ├── package-lock.json ├── package.json ├── schedule-monthly.js └── ui-debug.log
schedule-monthly.js代码
const functions = require("firebase-functions"); const admin = require("firebase-admin"); admin.initializeApp(); //firebase deploy --only "functions:schedule-monthly" // functions:fileName exports.scheduledFunction = functions.pubsub .schedule("30 8 * * *") .timeZone("America/Sao_Paulo") .onRun(() => { console.log("Triggering email") return null; });
部署命令
$firebase deploy --only "functions:schedule-monthly"
部署日志
=== Deploying to '****'... i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint > functions@ lint ****/functions > eslint . ✔ functions: Finished running predeploy script. i functions: preparing codebase default for deployment i functions: ensuring required API cloudfunctions.googleapis.com is enabled... i functions: ensuring required API cloudbuild.googleapis.com is enabled... i artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled... ✔ artifactregistry: required API artifactregistry.googleapis.com is enabled ✔ functions: required API cloudfunctions.googleapis.com is enabled ✔ functions: required API cloudbuild.googleapis.com is enabled ⚠ functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory. ⚠ functions: Please note that there will be breaking changes when you upgrade. ⚠ functions: You are using an old version of firebase-functions SDK (3.15.4). Please update firebase-functions SDK to >=3.20.0 i functions: preparing functions directory for uploading... i functions: packaged /****/functions (37.65 KB) for uploading ✔ functions: functions folder uploaded successfully i functions: cleaning up build files... ✔ Deploy complete!
已部署函数列表
$firebase functions:list ┌───────────────────────────────────────┬─────────┬──────────────────────────────────────────────────────┬─────────────┬────────┬──────────┐ │ Function │ Version │ Trigger │ Location │ Memory │ Runtime │ ├───────────────────────────────────────┼─────────┼──────────────────────────────────────────────────────┼─────────────┼────────┼──────────┤ │ create_transaction │ v1 │ https │ us-central1 │ 256 │ python39 │ ├───────────────────────────────────────┼─────────┼──────────────────────────────────────────────────────┼─────────────┼────────┼──────────┤ │ ext-firestore-send-email-processQueue │ v1 │ providers/cloud.firestore/eventTypes/document.write │ us-central1 │ 256 │ nodejs14 │ ├───────────────────────────────────────┼─────────┼──────────────────────────────────────────────────────┼─────────────┼────────┼──────────┤ │ hello_http │ v1 │ https │ us-central1 │ 256 │ python39 │ ├───────────────────────────────────────┼─────────┼──────────────────────────────────────────────────────┼─────────────┼────────┼──────────┤ │ listenReserveCreated │ v1 │ providers/cloud.firestore/eventTypes/document.create │ us-central1 │ 256 │ nodejs10 │
控制台截图


解决方案
修正部署命令的函数名称:部署命令指定的
functions:schedule-monthly与代码中导出的函数名scheduledFunction不匹配,正确命令应为:firebase deploy --only "functions:scheduledFunction"确保函数文件被加载:Firebase Functions默认仅加载
index.js,需在index.js中导入自定义函数文件:// index.js require('./schedule-monthly');升级firebase-functions SDK:当前使用的3.15.4版本低于要求的≥3.20.0,执行命令升级:
npm install --save firebase-functions@latest重新部署:完成上述步骤后,执行正确的部署命令,再通过
firebase functions:list验证是否部署成功。
内容的提问来源于stack exchange,提问作者Augusto
相关产品推荐
相关产品推荐

