【问题标题】:Failed to deploy Cloud Functions after upgrading to node 14升级到节点 14 后无法部署 Cloud Functions
【发布时间】:2021-08-23 14:08:18
【问题描述】:

在我的 package.json 中将我的 Firebase 项目的节点版本从节点 10 提升到节点 14 之后,如下所示:

...
  "engines": {
    "node": "14"
  },
...

每当我尝试部署函数时,Firebase 都会引发错误。

首先,我运行:

firebase deploy --only functions:foo

之后,控制台显示:


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> lint
> gts lint

version: 14
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> ttsc

✔  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (257.54 KB) for uploading
i  pubsub: ensuring required API pubsub.googleapis.com is enabled...
i  scheduler: ensuring required API cloudscheduler.googleapis.com is enabled...
✔  pubsub: required API pubsub.googleapis.com is enabled
✔  scheduler: required API cloudscheduler.googleapis.com is enabled
✔  functions: functions folder uploaded successfully
i  functions: updating Node.js 14 function foo(us-central1)...
✔  functions[foo(us-central1)]: Successful upsert schedule operation. 

Functions deploy had errors with the following functions:
        foo(us-central1)

To try redeploying those functions, run:
    firebase deploy --only "functions:foo"

To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

不幸的是,我无法从错误中获得太多日志:

通过运行:

firebase deploy --only functions:foo

我收到以下错误日志:

{"code":3,"message":"构建失败:> sharp@0.28.3 install /workspace/node_modules/sharp\n> (node install/libvips && node install/dll-copy && prebuild-install ) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)\n\nsharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.6/libvips-8.10.6-linux-x64.tar.br\n\n> protobufjs@6.10.2 postinstall /workspace/node_modules/protobufjs\n> node scripts/安装后\n\n\n> functions@undefined prepare /workspace\n> npm run compile\n\n\n> functions@ compile /workspace\n> ttsc\n\nsh: 1: ttsc: not found\nnpm ERR !code ELIFECYCLE\nnpm ERR!syscall spawn\nnpm ERR!file sh\nnpm ERR!errno ENOENT\nnpm ERR!functions@ compile:ttsc\nnpm ERR!spawn ENOENT\nnpm ERR!\nnpm ERR!函数失败@ 编译脚本。\nnpm ERR!这可能不是 npm 的问题。上面可能有额外的日志输出。\n\nnpm ERR!可以在以下位置找到此运行的完整日志:\nnpm ERR!/builder/home /.npm/_cacache/_logs/2021-06-06T04_27_25_637Z-debug.log\nnpm ERR! 代码 ELIFECYCLE\nnpm ERR!errno 1 \nnpm 错误!函数@undefined 准备:npm run compile\nnpm 错误!退出状态 1\nnpm 错误! \nnpm 错误! functions@undefined prepare 脚本失败。\nnpm ERR!这可能不是 npm 的问题。上面可能有额外的日志输出。\n\nnpm ERR!可以在以下位置找到此运行的完整日志:\nnpm ERR! /builder/home/.npm/_logs/2021-06-06T04_27_25_673Z-debug.log;错误 ID:beaf8772"}

另外,我的node版本是:

node --version

v14.17.0

【问题讨论】:

  • 如果您尝试使用 NodeJS 14 在本地运行您的代码,这是否有效?
  • 是的。代码在本地模拟器上构建并运行良好。不幸的是,在构建阶段在云中部署失败。我能够通过删除 ttypescriptsharp 依赖项来修复它。不过,我不确定为什么这些依赖项可以在本地工作,但无法在云端构建。

标签: google-cloud-functions


【解决方案1】:

从 Google Cloud Console 查看Cloud Build 后,我注意到以下错误:

2021-06-07T03:28:00.714478581ZStep #4 - “builder”: src/cloud_functions/userInfo/https/onCall/uploadAvatar.ts(4,19):错误 TS7016:找不到模块的声明文件'锋利的'。 '/workspace/node_modules/sharp/lib/index.js' 隐含了一个 'any' 类型。

为了解决这个问题,我只是在 tsconfig.json 中添加了以下代码:

{
    "compilerOptions": {
        "noImplicitAny": false,
        ...
    },
    ...
}

【讨论】:

    猜你喜欢
    • 2020-06-03
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 2020-11-08
    • 2017-09-01
    • 1970-01-01
    • 2021-03-05
    • 2016-03-31
    相关资源
    最近更新 更多