Sharp 在 AWS Amplify 后端 Lambda 上导致构建失败

Tur*_*ner 3 node.js aws-lambda sharp aws-amplify

我对 aws amplify 还很陌生,并且有一个 amplify 应用程序,它有一个后端 lambda 函数,该函数使用Sharp作为依赖项。当我推送 git 来触发部署时,我的构建失败了,我认为是由于vips/vips8没有找到尖锐的依赖关系。

相关日志

2022-05-31T18:26:18.714Z [INFO]: [0mError: Packaging lambda function failed with the error [0m
                                 [0mCommand failed with exit code 1: npm install --no-bin-links --production[0m
                                 [0msh: prebuild-install: command not found[0m
                                 [0m../src/common.cc:24:10: fatal error: vips/vips8:  [0m
                                 [0m #include <vips/vips8>[0m
                                 [0m          ^~~~~~~~~~~~[0m
                                 [0mcompilation terminated.[0m
                                 [0mmake: *** [Release/obj.target/sharp-linux-x64/src/common.o] Error 1[0m
                                 [0mgyp ERR! build error [0m
                                 [0mgyp ERR! stack Error: `make` failed with exit code: 2[0m
                                 [0mgyp ERR! stack     at ChildProcess.onExit (/root/.nvm/versions/node/v14.19.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)[0m
                                 [0mgyp ERR! stack     at ChildProcess.emit (events.js:400:28)[0m
                                 [0mgyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:282:12)[0m
                                 [0mgyp ERR! System Linux 4.14.246-187.474.amzn2.x86_64[0m
                                 [0mgyp ERR! command "/root/.nvm/versions/node/v14.19.0/bin/node" "/root/.nvm/versions/node/v14.19.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"[0m
                                 [0mgyp ERR! cwd /codebuild/output/src927006233/src/create-react-app-auth-amplify/amplify/backend/function/S3Trigger71b5b76d/src/node_modules/sharp[0m
                                 [0mgyp ERR! node -v v14.19.0[0m
                                 [0mgyp ERR! node-gyp -v v5.1.0[0m
                                 [0mgyp ERR! not ok [0m
                                 [0mnpm WARN S3Trigger71b5b76d@2.0.0 No repository field.[0m
Run Code Online (Sandbox Code Playgroud)

跑步amplify push打包 lambda 并部署它,工作完全正常,问题只出现在它从 github 拉取并尝试通过 amplify 构建平台运行时。我正在运行节点 v 16

感谢您的任何想法!我的 google-foo 这次失败了。

小智 5

根据AWS Lambda 安装指南,您可以将以下命令作为预安装脚本添加到Amplify lambda 的package.json 中:

{
  "name": "file-storage-get-s3-signed-link",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "preinstall": "SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux --libc=glibc sharp"
  }
}
Run Code Online (Sandbox Code Playgroud)