简体   繁体   English

错误:darwin-x64' 二进制文件不能在 'linux-x64' 平台上使用(AWS lambda + typescript + webpack 锐模块)

[英]Error: darwin-x64' binaries cannot be used on the 'linux-x64' platform (AWS lambda + typescript + webpack sharp module )

aws lambda with typescript is occured error when bundle by webpack. aws lambda 和 typescript 在由 webpack 捆绑时发生错误。

Before bundle webpack, I did "npm i --arch=x64 --platform=linux --target=12.14.1 sharp" and labmda is working properly.在捆绑 webpack 之前,我做了“npm i --arch=x64 --platform=linux --target=12.14.1 sharp”,labmda 工作正常。

But, lambda upload zip size is more and more larger.但是,lambda上传zip尺寸越来越大。

so, I want to resize lambda upload zip size using serverless-webpack.所以,我想使用 serverless-webpack 调整 lambda 上传 zip 的大小。

Image lambda is working well except using sharp module. Image lambda 除了使用夏普模块外工作良好。

I don't know how to do.我不知道该怎么做。

I did :我做了

  1. Delete node_modules and package-lock.json and install dependencies ( also installed sharp )删除 node_modules 和 package-lock.json 并安装依赖项(也安装了sharp)
  2. Delete node_modules/sharp and install sharp ( lambda environment - linux, x64, node version )删除node_modules/sharp并安装sharp(lambda环境-linux,x64,节点版本)
  3. Set serverless-webpack configuration in serverless: packagerOptions ( scrips ) - rebuild sharp lambda enviroment在 serverless 中设置 serverless-webpack 配置:packagerOptions ( scrips ) - 重建锐利的 lambda 环境

But, lambda is not working properly.但是,lambda 工作不正常。

and I looked many informations.我看了很多信息。

[lambda linux env] [λ linux 环境]
Error running Sharp inside AWS Lambda function: darwin-x64' binaries cannot be used on the 'linux-x64' platform 在 AWS Lambda function 中运行 Sharp 时出错:darwin-x64 二进制文件不能在“linux-x64”平台上使用

[Serverless-webpack] [无服务器-webpack]
https://github.com/serverless-heaven/serverless-webpack/issues/396 https://github.com/serverless-heaven/serverless-webpack/issues/396

Thank you!谢谢!


[Edit] [编辑]

My local env: Mac我的本地环境:Mac

production env: linux生产环境:linux

Maybe, I think that npm command with "--platform" is not working in mac.也许,我认为带有“--platform”的 npm 命令在 mac 中不起作用。

Additionally, I solved this problem using aws codebuild.此外,我使用 aws codebuild 解决了这个问题。

I posted answer.我发布了答案。

But, It is not working in my local [ Mac ]但是,它在我的本地 [Mac] 中不起作用

I got it working by telling webpack to reinstall the package after it runs npm install:我通过告诉 webpack 在运行 npm 安装后重新安装 package 来使其工作:

webpack:
  includeModules:
    forceExclude:
      - aws-sdk
  packagerOptions:
    scripts:
      - rm -rf node_modules/sharp
      - npm install --arch=x64 --platform=linux sharp

I solved this problem using aws codebuild.我使用 aws codebuild 解决了这个问题。

codebuild has linux and node.js runtime. codebuild 有 linux 和 node.js 运行时。

So, I ran below command in aws codebuild ( https://sharp.pixelplumbing.com/install )因此,我在 aws codebuild 中运行了以下命令( https://sharp.pixelplumbing.com/install

rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux sharp

sharp module works properly.锋利的模块工作正常。

I got it working by using sam cli to build using this command我通过使用 sam cli 使用此命令构建它来工作

sam build -u

This command builds the code inside a container that has the similar environments as lambda此命令在与 lambda 具有相似环境的容器内构建代码

Dave Cowart's answer helped me a lot but having multiple lambda functions in the repo, I didn't want to install sharp into all of my functions. Dave Cowart 的回答对我帮助很大,但是在 repo 中有多个 lambda 函数,我不想在我的所有函数中安装Sharp。

Here's my solution:这是我的解决方案:

serverless.yml

  webpack:
    webpackConfig: 'webpack.config.js'
    includeModules:
      forceExclude:
        - aws-sdk
    packagerOptions:
      scripts:
        - rm -rf node_modules/sharp
        - npm install --production --arch=x64 --platform=linux

You don't actually need to specify sharp in the install script.您实际上不需要在安装脚本中指定Sharp。 Making it a generic npm install means it will only reinstall sharp if it's in the package.json (which it won't be if it's not used due to webpack tree shaking). Making it a generic npm install means it will only reinstall sharp if it's in the package.json (which it won't be if it's not used due to webpack tree shaking).

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “darwin-arm64v8”二进制文件不能在“darwin-x64”平台上使用 - 'darwin-arm64v8' binaries cannot be used on the 'darwin-x64' platform linux-x64 二进制文件无法在 linuxmusl-x64 平台上使用错误 - linux-x64 binaries cannot be used on the linuxmusl-x64 platform error 错误:找不到模块“../node-v11-darwin-x64/node_sqlite3.node” - ERROR: Cannot find module '../node-v11-darwin-x64/node_sqlite3.node' fsevents@2.3.2 不受支持的平台:github 上需要 {"os":"darwin","arch":"any"}(当前:{"os":"linux","arch":"x64"})动作 - Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) on github actions 错误:在 Process.ChildProcess._handle.onexit 产生 /{{org}}/dist/node_modules/@ffmpeg-installer/linux-x64/ffmpeg EACCES - Error: spawn /{{org}}/dist/node_modules/@ffmpeg-installer/linux-x64/ffmpeg EACCES at Process.ChildProcess._handle.onexit 错误:找不到模块 'node-linux-x64/package.json' - 第一次推送到 Heroku - Error: Cannot find module 'node-linux-x64/package.json' - pushing to Heroku for first time 推送到Heroku时出错:找不到模块“ node-linux-x64 / package.json” - Error while pushing to Heroku: Cannot find module 'node-linux-x64/package.json' sharp Prebuilt libvips 8.10.5 二进制文件尚不适用于 darwin-arm64v8 - sharp Prebuilt libvips 8.10.5 binaries are not yet available for darwin-arm64v8 在laravel-echo-server中找不到模块'node-v46-linux-x64 / node_sqlite3.node'错误 - Cannot find module 'node-v46-linux-x64/node_sqlite3.node' error in laravel-echo-server 无法推送到 Heroku:找不到模块“node-linux-x64/package.json” - Unable to push to Heroku: Cannot find module 'node-linux-x64/package.json'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM