firebase - 什么是functions.yaml

标签 firebase google-cloud-firestore google-cloud-functions

当我尝试部署 Firebase 函数时,使用 --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')

我不明白日志“无法找到functions.yaml。必须使用http发现”的这一部分。我读过这个答案Firebase Deployment failure - Could not find functions.yaml. Must use http discovery 1. 和 2. 设置正确(我之前部署时从未遇到过问题),并且我尝试重新运行 firebase init,但没有任何改进。我也尝试过删除服务器上的所有功能。

什么是functions.yaml?

  1. 我应该拥有一个吗? (我在磁盘上找不到该名称的文件)
  2. 它应该位于哪里?
  3. 我应该在文件中放入什么内容?
  4. 在哪里可以找到有关functions.yaml的文档?

最佳答案

functions.yaml 是 firebase 生成的文件,用于确定项目源代码中存在哪些类型的函数。开发人员不应编写此文件,并且开发人员不宜对其进行修改。这解释了文件中缺少的文档。

您看到的日志来自这里: https://github.com/firebase/firebase-tools/blob/06b8bad39e8f92f9f348a751076fc016b6583a79/src/deploy/functions/runtimes/discovery/index.ts#L47

您遇到的错误似乎是由格式错误的functions.yaml引起的,可能是由于部署操作中的错误,也可能是项目函数源中的错误。

可能相关的错误:https://github.com/firebase/firebase-tools/issues/5673

关于firebase - 什么是functions.yaml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76121723/

相关文章:

node.js - 修复由于多次 firebase 初始化导致的 Firebase 错误

firebase - 使用 order by 子句时 Flutter Firestore 流不会更新

firebase - 是否需要更改软件包名称?

javascript - 根据查询更新 Cloud Firestore 中的文档

javascript - 添加自定义声明返回错误 auth/invalid-email :The email address is improperly formatted with Firebase Functions

Firebase 云函数触发器

typescript - 警告,缺少 FIREBASE_CONFIG 和 GCLOUD_PROJECT 环境变量。初始化 firebase-admin 将失败

ios - Firebase 观察方法 - 零星停机?

angular - Firebase firestore 不能与 Angular Universal 一起使用 : package. json 不存在

node.js - Firebase 经过身份验证的 HTTP 端点 - 云功能,它们安全吗?