Google Cloud Function/Firebase Function 部署停止工作:"unexpected end of file"

Google Cloud Function / Firebase Function deployment stops working: "unexpected end of file"

部署我们的 Firebase 功能最近突然停止工作。 运行 firebase functions:log 提供了一个不是很有帮助的见解:

2022-02-15T06:53:12.421579Z E XXX: {"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":3,"message":"Build failed: curl: (22) The requested URL returned error: 404 \n\ngzip: stdin: unexpected end of file\ntar: Child returned status 1\ntar: Error is not recoverable: exiting now; Error ID: 08522105"},"authenticationInfo":{"principalEmail":"XXXX"},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","resourceName":"XXXX"}

其他项目的部署工作正常,但即使是该项目的旧版本(过去已成功部署的项目)也会失败。

firebase 日志根本没有用,但由于函数是使用“Google Cloud Build”构建的,因此我能够通过在 Google 中打开日志资源管理器来更深入地了解问题所在云控制台。 Select 资源类型“Cloud Build”,您将在其中找到每个构建步骤的日志以及失败的步骤。

在这种情况下,它无法获取 package.json (1.22) 中特定的 yarn-version。将其更改为“1.22.17”(目前最新)修复了构建。

"engines": {
    "node": "14",
    "npm": "8.1",
    "yarn": "1.22.17"
},

我在部署时收到来自 gcloud.functions.deploy 的 404 错误:

Deploying function (may take a while - up to 2 minutes)...
.
For Cloud Build Stackdriver Logs, visit: https://console.cloud.google.com/logs/viewer?project=x-xxx-dev&advancedFilter=resource.type%3Dbuild%0Aresource.labels.build_id%3D35aac420-xx-4cd1-b7be-blah%0AlogName%3Dprojects%2Fxxx-xxx-dev%2Flogs%2Fcloudbuild
................failed.
ERROR: (gcloud.functions.deploy) OperationError: code=3, message=Build failed: curl: (22) The requested URL returned error: 404 

此处看不到根本原因错误,但如果您单击控制台输出中的 Stackdriver 日志 link,将会有更多详细信息。就我而言,根本错误是无法下载 yarn 2.4.3 @ https://github.com/yarnpkg/yarn/releases/download/v2.4.3/yarn-v2.4.3.tar.gz

我没想到此时会使用纱线 2(浆果),但在我的 package.json 中我没有明确说明:

 "engines": {
    ...
    "yarn": ">=1.22.0"
  },

通过更改为仅接受版本 1,问题已解决:

 "engines": {
    ...
    "yarn": "^1.22.0"
  },

我还是不明白为什么 npm 解决了这个缺失的版本。