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

Firebase Functions部署报错及functions.yaml相关问题咨询

Firebase Functions部署错误排查与functions.yaml相关问题

问题背景

部署Firebase Functions时使用--debug选项遇到如下错误日志:

[2023-04-27T14:33:31.762Z] > [functions] package.json contents: {
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "watch": "tsc --watch",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log",
    "emulate-functions": "~/projects/scripts/kill-emulator.sh | tsc -w | firebase emulators:start --only functions --inspect-functions",
    "emulate-debug": "~/projects/scripts/kill-emulator.sh | tsc -w | firebase emulators:start --inspect-functions",
    "emulate": "kill-emulator.sh | tsc -w | firebase emulators:start"
  },
  "comments": {
    "emulate-functions": "Can be used to debug HTTP callable cloud functions. To debug cloud triggered function firestore emulator must be running. Because of debugger support, functions will not be running in parallel",
    "emulate-debug": "Runs all emulators with the functions debugging enabled",
    "emulate": "Runs all emulator with the fungtions debugger disabled. Give the best emulation, but functions cannot be debugged",
    "note1": "npm run emulate -- --import=seeds/latest --export-on-exit=seeds/latest will run the emulator with persistant data. (seeds folder must exist, before you start)",
    "note2": "Emulator is best run from the functions folder. If it is run from the docavea folder, functions code does not reload correctly"
  },
  "main": "lib/src/index.js",
  "dependencies": {
    "@sendgrid/mail": "^7.7.0",
    "api2pdf": "^1.1.1",
    "axios": "^0.19.2",
    "firebase-admin": "^11.7.0",
    "firebase-functions": "^4.3.1",
    "firebase-tools": "^11.28.0",
    "googleapis": "^111.0.0",
    "lodash": "^4.17.21",
    "mailchimp-api-v3": "^1.13.1",
    "md5": "^2.2.1",
    "onedrive-api": "^1.0.4",
    "pdf-lib": "^1.17.1",
    "php-serialize": "^3.0.1",
    "source-map-support": "^0.5.21"
  },
  "engines": {
    "node": "16"
  },
  "devDependencies": {
    "@types/lodash": "^4.14.191",
    "@types/node": "^16",
    "@types/php-serialize": "^3.0.0",
    "@typescript-eslint/eslint-plugin": "^5.53.0",
    "@typescript-eslint/parser": "^5.53.0",
    "eslint": "^8.39.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.27.5",
    "typescript": "^4.9.5"
  },
  "private": true
}
[2023-04-27T14:33:31.763Z] Building nodejs source
[2023-04-27T14:33:31.764Z] Could not find functions.yaml. Must use http discovery
[2023-04-27T14:33:32.064Z] Serving at port 9005

[2023-04-27T14:33:42.426Z] Got response from /__/functions.yaml Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'storage')
[2023-04-27T14:33:42.428Z] Failed to parse functions.yamlincomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 60:
     ...  from function source: TypeError: Cannot read properties of unde ... 
                                         ^ {"name":"YAMLException","reason":"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line","mark":{"name":null,"buffer":"Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'storage')\n\u0000","position":59,"line":0,"column":59},"message":"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 60:\n     ...  from function source: TypeError: Cannot read properties of unde ... \n                                         ^"}
[2023-04-27T14:33:42.446Z] shutdown requested via /__/quitquitquit


Error: Failed to load function definition from source: Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'storage')

已确认本地配置无误(此前部署正常),尝试过重新执行firebase init、删除服务器上所有函数均无改善,现咨询:

  1. 是否需要拥有functions.yaml文件?(本地磁盘找不到该文件)
  2. 该文件应放置在何处?
  3. 文件中应填写什么内容?
  4. 在哪里可以找到functions.yaml的相关文档?

问题解答

1. 是否需要functions.yaml文件?

不需要。functions.yaml是Firebase CLI在部署或运行模拟器时自动生成的临时文件,用于描述函数元数据(比如触发器类型、入口点等),完全不需要用户手动创建。日志里的Could not find functions.yaml. Must use http discovery只是CLI的正常流程提示,并非导致部署失败的原因。

2. 该文件应放置在何处?

如果手动创建(不推荐),需放在Functions目录根目录下(和package.json同级),但实际上CLI会自动管理这个文件的生成与存放,用户无需关心具体位置。

3. 文件中应填写什么内容?

用户不需要手动编写functions.yaml,它的内容由CLI根据你的函数代码自动生成。示例结构大致如下(仅作参考,不要手动修改):

functions:
  - name: your-function-name
    entryPoint: yourFunctionExportName
    trigger:
      httpsTrigger: {}
    runtime: nodejs16

4. 相关文档在哪里?

Firebase官方文档中没有单独针对functions.yaml的公开文档,因为它是CLI内部使用的文件,用户无需手动操作。所有关于Functions部署的配置,都通过代码(比如functions.https.onRequest等触发器定义)和firebase.json完成。


实际错误根源

部署失败的核心原因是日志中的TypeError: Cannot read properties of undefined (reading 'storage')——这说明你的函数代码中尝试访问一个未定义对象的storage属性。比如可能是firebase-admin初始化有问题,导致admin.storage()返回undefined,或者你引用了未正确初始化的变量。

建议检查:

  • 是否在函数代码开头正确执行了admin.initializeApp()初始化Firebase Admin
  • 排查所有使用.storage的代码位置,确认前置对象已正确定义和初始化

内容的提问来源于stack exchange,提问作者Jørgen Rasmussen

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 15:47:32