Firebase CF 仪表板中出现“某些功能加载失败”错误消息
以下 typescript 函数根据 Firebase CLI 成功部署,但根据仪表板部署失败。
import * as functions from 'firebase-functions';
export const helloWorld = functions.https.onRequest((request, response) => {
response.send("hello world");
});
这是我的控制台日志:
filippo@MacBook-Air-di-Filippo Cloud Functions % firebase deploy --only functions
=== Deploying to 'my-project-00000'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> eslint --ext .js,.ts .
Running command: npm --prefix "$RESOURCE_DIR" run build
> build
> tsc
✔ 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 cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8313
i functions: cleaning up build files...
✔ Deploy complete!
我主要遵循了这些教程: https://youtu.be/2u6Zb36OQjM?si=qxZd8G2hyIFYNRjq , https://firebase.google.com/docs/functions/get-started?gen=2nd 。
不可否认,我的 Typescript 代码可能是问题所在。
环境
Visual Studio Code 1.88.1
Node 20.12.0
ESLint 9.0.0
Firebase CLI 13.7.3
Safari 17.4.1 (macOS 14.4.1),还有 Chrome 122.0.6261.94
MacBook Air M1 8GB
编辑
注意:我已经联系了 Firebase 支持,但他们可能已经停止了回复。
问这个问题没有问题,因为它总是包含对代码本身的担忧,如果问题能够解决,它可以节省拥有它的人和 Firebase 支持人员的时间。
在部署函数之前,我尝试从函数目录内部运行 npm install,我也尝试登录和退出 Firebase CLI。
无论如何,如果我按照 Firebase 支持人员的建议运行
firebase --debug --only functions deploy
,以下部分会引起我的注意:
- [functions] 服务帐户 IAM 检查错误,部署可能失败:HTTP 错误:404,未知服务帐户
- 部署了 0 个函数
但其他许多人也可能如此。如果您好奇,这里是完整的控制台日志:
filippo@MacBook-Air-di-Filippo Cloud Functions % firebase --debug --only functions deploy
[2024-04-23T08:29:34.687Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2024-04-23T08:29:34.688Z] > authorizing via signed-in user ([email protected])
[2024-04-23T08:29:34.688Z] [iam] checking project my-project-00000 for permissions ["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]
[2024-04-23T08:29:34.688Z] > refreshing access token with scopes: []
[2024-04-23T08:29:34.689Z] >>> [apiv2][query] POST https://www.googleapis.com/oauth2/v3/token [none]
[2024-04-23T08:29:34.689Z] >>> [apiv2][body] POST https://www.googleapis.com/oauth2/v3/token [omitted]
[2024-04-23T08:29:35.398Z] <<< [apiv2][status] POST https://www.googleapis.com/oauth2/v3/token 200
[2024-04-23T08:29:35.398Z] <<< [apiv2][body] POST https://www.googleapis.com/oauth2/v3/token [omitted]
[2024-04-23T08:29:35.406Z] >>> [apiv2][query] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-project-00000:testIamPermissions [none]
[2024-04-23T08:29:35.406Z] >>> [apiv2][(partial)header] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-project-00000:testIamPermissions x-goog-quota-user=projects/my-project-00000
[2024-04-23T08:29:35.407Z] >>> [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-project-00000:testIamPermissions {"permissions":["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]}
[2024-04-23T08:29:35.557Z] <<< [apiv2][status] GET https://firebase-public.firebaseio.com/cli.json 200
[2024-04-23T08:29:35.558Z] <<< [apiv2][body] GET https://firebase-public.firebaseio.com/cli.json {"cloudBuildErrorAfter":1594252800000,"cloudBuildWarnAfter":1590019200000,"defaultNode10After":1594252800000,"minVersion":"3.0.5","node8DeploysDisabledAfter":1613390400000,"node8RuntimeDisabledAfter":1615809600000,"node8WarnAfter":1600128000000}
[2024-04-23T08:29:36.541Z] <<< [apiv2][status] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-project-00000:testIamPermissions 200
[2024-04-23T08:29:36.542Z] <<< [apiv2][body] POST https://cloudresourcemanager.googleapis.com/v1/projects/my-project-00000:testIamPermissions {"permissions":["cloudfunctions.functions.create","cloudfunctions.functions.delete","cloudfunctions.functions.get","cloudfunctions.functions.list","cloudfunctions.functions.update","cloudfunctions.operations.get","firebase.projects.get"]}
[2024-04-23T08:29:36.543Z] >>> [apiv2][query] POST https://iam.googleapis.com/v1/projects/my-project-00000/serviceAccounts/[email protected]:testIamPermissions [none]
[2024-04-23T08:29:36.543Z] >>> [apiv2][body] POST https://iam.googleapis.com/v1/projects/my-project-00000/serviceAccounts/[email protected]:testIamPermissions {"permissions":["iam.serviceAccounts.actAs"]}
[2024-04-23T08:29:37.095Z] <<< [apiv2][status] POST https://iam.googleapis.com/v1/projects/my-project-00000/serviceAccounts/[email protected]:testIamPermissions 404
[2024-04-23T08:29:37.095Z] <<< [apiv2][body] POST https://iam.googleapis.com/v1/projects/my-project-00000/serviceAccounts/[email protected]:testIamPermissions {"error":{"code":404,"message":"Unknown service account","status":"NOT_FOUND"}}
[2024-04-23T08:29:37.096Z] [functions] service account IAM check errored, deploy may fail: HTTP Error: 404, Unknown service account {"name":"FirebaseError","children":[],"context":{"body":{"error":{"code":404,"message":"Unknown service account","status":"NOT_FOUND"}},"response":{"statusCode":404}},"exit":1,"message":"HTTP Error: 404, Unknown service account","status":404}
=== Deploying to 'my-project-00000'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> lint
> eslint --ext .js,.ts .
Running command: npm --prefix "$RESOURCE_DIR" run build
> build
> tsc
✔ functions: Finished running predeploy script.
[2024-04-23T08:29:42.019Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/my-project-00000 [none]
[2024-04-23T08:29:42.669Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/my-project-00000 200
[2024-04-23T08:29:42.669Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/my-project-00000 {"projectId":"my-project-00000","projectNumber":"849399059679","displayName":"Hello Pizza","name":"projects/my-project-00000","resources":{"hostingSite":"my-project-00000"},"state":"ACTIVE","etag":"1_8d259d27-e405-4f7a-9cfa-87297ca89976"}
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...
[2024-04-23T08:29:42.673Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/cloudfunctions.googleapis.com [none]
[2024-04-23T08:29:42.673Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/cloudfunctions.googleapis.com x-goog-quota-user=projects/my-project-00000
[2024-04-23T08:29:42.675Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/runtimeconfig.googleapis.com [none]
[2024-04-23T08:29:42.676Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/runtimeconfig.googleapis.com x-goog-quota-user=projects/my-project-00000
[2024-04-23T08:29:42.677Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/cloudbuild.googleapis.com [none]
[2024-04-23T08:29:42.677Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/cloudbuild.googleapis.com x-goog-quota-user=projects/my-project-00000
[2024-04-23T08:29:42.678Z] >>> [apiv2][query] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/artifactregistry.googleapis.com [none]
[2024-04-23T08:29:42.678Z] >>> [apiv2][(partial)header] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/artifactregistry.googleapis.com x-goog-quota-user=projects/my-project-00000
[2024-04-23T08:29:44.092Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/runtimeconfig.googleapis.com 200
[2024-04-23T08:29:44.093Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/runtimeconfig.googleapis.com [omitted]
[2024-04-23T08:29:44.094Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/artifactregistry.googleapis.com 200
[2024-04-23T08:29:44.094Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/artifactregistry.googleapis.com [omitted]
✔ artifactregistry: required API artifactregistry.googleapis.com is enabled
[2024-04-23T08:29:44.111Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/cloudfunctions.googleapis.com 200
[2024-04-23T08:29:44.111Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/cloudfunctions.googleapis.com [omitted]
✔ functions: required API cloudfunctions.googleapis.com is enabled
[2024-04-23T08:29:44.187Z] <<< [apiv2][status] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/cloudbuild.googleapis.com 200
[2024-04-23T08:29:44.187Z] <<< [apiv2][body] GET https://serviceusage.googleapis.com/v1/projects/my-project-00000/services/cloudbuild.googleapis.com [omitted]
✔ functions: required API cloudbuild.googleapis.com is enabled
[2024-04-23T08:29:44.188Z] >>> [apiv2][query] GET https://firebase.googleapis.com/v1beta1/projects/my-project-00000/adminSdkConfig [none]
[2024-04-23T08:29:44.478Z] <<< [apiv2][status] GET https://firebase.googleapis.com/v1beta1/projects/my-project-00000/adminSdkConfig 200
[2024-04-23T08:29:44.478Z] <<< [apiv2][body] GET https://firebase.googleapis.com/v1beta1/projects/my-project-00000/adminSdkConfig {"projectId":"my-project-00000","storageBucket":"my-project-00000.appspot.com"}
[2024-04-23T08:29:44.478Z] >>> [apiv2][query] GET https://runtimeconfig.googleapis.com/v1beta1/projects/my-project-00000/configs [none]
[2024-04-23T08:29:45.120Z] <<< [apiv2][status] GET https://runtimeconfig.googleapis.com/v1beta1/projects/my-project-00000/configs 200
[2024-04-23T08:29:45.120Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/my-project-00000/configs {}
[2024-04-23T08:29:45.123Z] Validating nodejs source
[2024-04-23T08:29:45.853Z] > [functions] package.json contents: {
"name": "functions",
"scripts": {
"lint": "eslint --ext .js,.ts .",
"build": "tsc",
"build:watch": "tsc --watch",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "18"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^11.8.0",
"firebase-functions": "^4.3.1"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint": "^8.9.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-import": "^2.25.4",
"firebase-functions-test": "^3.1.0",
"typescript": "^4.9.0"
},
"private": true
}
[2024-04-23T08:29:45.853Z] Building nodejs source
i functions: Loading and analyzing source code for codebase default to determine what to deploy
[2024-04-23T08:29:45.854Z] Could not find functions.yaml. Must use http discovery
[2024-04-23T08:29:45.861Z] Found firebase-functions binary at '/Users/filippo/Library/Mobile Documents/com~apple~CloudDocs/Cloud Functions/functions/node_modules/.bin/firebase-functions'
Serving at port 8882
[2024-04-23T08:29:45.999Z] Got response from /__/functions.yaml {"endpoints":{},"specVersion":"v1alpha1","requiredAPIs":[]}
[2024-04-23T08:29:51.017Z] >>> [apiv2][query] GET https://cloudfunctions.googleapis.com/v1/projects/my-project-00000/locations/-/functions [none]
[2024-04-23T08:29:51.932Z] <<< [apiv2][status] GET https://cloudfunctions.googleapis.com/v1/projects/my-project-00000/locations/-/functions 200
[2024-04-23T08:29:51.932Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v1/projects/my-project-00000/locations/-/functions {}
[2024-04-23T08:29:51.935Z] >>> [apiv2][query] GET https://cloudfunctions.googleapis.com/v2/projects/my-project-00000/locations/-/functions filter=environment%3D%22GEN_2%22
[2024-04-23T08:29:53.026Z] <<< [apiv2][status] GET https://cloudfunctions.googleapis.com/v2/projects/my-project-00000/locations/-/functions 200
[2024-04-23T08:29:53.027Z] <<< [apiv2][body] GET https://cloudfunctions.googleapis.com/v2/projects/my-project-00000/locations/-/functions {}
[2024-04-23T08:29:53.037Z] Total Function Deployment time: 0
[2024-04-23T08:29:53.037Z] 0 Functions Deployed
[2024-04-23T08:29:53.037Z] 0 Functions Errored
[2024-04-23T08:29:53.037Z] 0 Function Deployments Aborted
[2024-04-23T08:29:53.037Z] Average Function Deployment time: NaN
i functions: cleaning up build files...
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/my-project-00000/overview
我如何查明问题?
将此内容作为社区 wiki 分享,以造福他人
正如 @Doug Stevenson 所提到的
There is an error message on your console screenshot in the upper right. That seems like it could be masking the underlying problem. If you're having problems with the console that you don't understand, contact Firebase support directly about it, since there is not much the volunteers here can do about it.
此外,您还可以执行以下故障排除选项:
-
查看 Firebase 日志 。您也可以通过控制台、Cloud Logging UI 或 firebase CLI 查看日志
-
查看此 Stackoverflow 帖子 。您可以在部署函数之前在函数目录中运行
npm install
。 -
您可以联系 Firebase 支持 以进一步了解您的案例。
将 Firebase CLI 更新至版本 13.7.5 后,我尝试重新部署我的函数,但 ESLint 无缘无故地给我带来了问题,因此我运行了
cd functions && npx eslint . --fix
,修复了该问题,然后我的
helloWorld()
函数重新部署成功。