node.js - 使用 Sharp 库的 Firebase 部署功能在 Google Cloud Build 中失败

标签 node.js firebase google-cloud-functions google-cloud-build sharp

从 Bitbucket Pipelines 迁移到 Google Cloud Build 后,Firebase 部署失败。该设置已在 Bitbucket Pipelines 和本地成功部署。

除了下面的错误之外,没有给出进一步的解释。我对代码的某些部分进行了注释,以认识到“const Sharp = require('sharp')”是导致构建失败的一个命令。

但是没有明显的原因导致“firebase部署”因“require('sharp')”而失败,我必须想办法解决这个问题。

Firebase 在 Google Cloud Build 中部署输出

Step #5: === Deploying to 'werkout-staging-b1483'...
Step #5: 
Step #5: i  deploying functions
Step #5: ✔  functions: Finished running predeploy script.
Step #5: i  functions: ensuring necessary APIs are enabled...
Step #5: ✔  functions: all necessary APIs are enabled
Step #5: i  functions: preparing functions/cloud_functions directory for uploading...
Step #5: 
Step #5: Error: There was an unknown problem while trying to parse function triggers. Please ensure you are using Node.js v6 or greater.
Finished Step #5
ERROR
ERROR: build step 5 "gcr.io/werkout-staging-b1483/firebase" failed: exit status 2

Dockerfile

FROM cypress/base:10.15.3

#CMD ["node"]

RUN npm install -g firebase-tools@^7.0.0
ENTRYPOINT ["/usr/local/bin/firebase"]

有什么想法吗?

最佳答案

这次我真的明白了。

我运行 npm ci 来构建云功能,然后使用 firebase deploy 将它们部署到云中。问题是,正如您在上面的 docker 文件中看到的那样,gcr.io/$PROJECT_ID/firebase 镜像是使用 Node 10.15.3 构建的,而 gcr.io/cloud-builders/npm 使用 Node 8。夏普过于挑剔,因此未能 build 。

最糟糕的是,firebase 对此非常保密,除了纯粹的猜测之外,我没有任何线索可以解决。

- name: 'gcr.io/cloud-builders/npm'
  args: [ 'run', 'build' ]

- name: 'gcr.io/$PROJECT_ID/firebase'
  args: [ 'firebase', 'deploy' ]

解决办法:

- name: 'gcr.io/cloud-builders/npm:node-10.10.0'
  args: [ 'run', 'build' ]

- name: 'gcr.io/$PROJECT_ID/firebase'
  args: [ 'firebase', 'deploy' ]

这应该与云函数package.json中指定的 Node 引擎版本匹配。

关于node.js - 使用 Sharp 库的 Firebase 部署功能在 Google Cloud Build 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56675535/

相关文章:

reactjs - Firebase 配置中的 React 环境变量错误 'Unexpected token'

node.js - 每次我做一个小改动时我都必须重新加载 app.js 吗?

javascript - 使用无效数据调用函数 DocumentReference.set()。不支持的字段值 : a function (found in field dispatch)"

node.js - Ionic/bower/cordova - 忽略构建文件

java - Firebase实时数据库: How to use onDisconnect

angular - 等到触发器在 ionic-angular 的 firebase 上被触发

node.js - 无法使用 Admin SDK Firebase 获取用户列表

javascript - Firebase 'Unhandled Rejection' 和 'Can' t 在设置 header 后设置“JavaScript 错误

javascript - 仅在流结束后才解决 Promise

javascript - ajax:如何从数据库获取数据到html?