aws-samples / image-optimization

Simple, performant and cost efficient solution for optimizing images using Amazon CloudFront, Amazon S3 and AWS Lambda
MIT No Attribution
195 stars 116 forks source link

Could not load the \"sharp\" module using the linux-x64 runtime\nPossible #40

Closed eyyazubi closed 3 months ago

eyyazubi commented 5 months ago

i got:

"errorType": "Error", "errorMessage": "Could not load the \"sharp\" module using the linux-x64 runtime\nPossible solutions:\n- Ensure optional dependencies can be installed:\n npm install --include=optional sharp\n yarn add sharp --ignore-engines\n- Ensure your package manager supports multi-platform installation:\n See https://sharp.pixelplumbing.com/install#cross-platform\n- Add platform-specific dependencies:\n npm install --os=linux --cpu=x64 sharp\n- Consult the installation documentation:\n See https://sharp.pixelplumbing.com/install"...

and fixed with root package.json line 8: prev: "prebuild": "npm install sharp --prefix functions/image-processing/ --os=linux --cpu=x64"

TO: "prebuild": "npm install --force sharp --prefix functions/image-processing/ --os=linux --cpu=x64"

achrafsouk commented 5 months ago

It did not work for me (i am using Mac)

eyyazubi commented 5 months ago

I also use mac. I haven't tested it at all on the mac. It comes in Lambda functions on aws.

i had a "internal error" message, when i try visit to the images via cloudfront url and saw the error in the lambda functions under code source.

found this post regarding sharp and linux-x64 runtime: https://github.com/lovell/sharp/issues/4001

maiconcarraro commented 5 months ago

I had this error because I deployed without running the build before, after running the build it was working fine. I'm using node v22 and npm 10.6.0.

dimasxp commented 4 months ago

have the same problem, changed node version from 18 to 20,rebuild, now works fine

ishanaudichya commented 4 months ago

It did not work for me (i am using Mac)

I think u re using an arm machine so the binary for sharp are not created image

This will work fine on x86 machines. To get around this use post build instead of prebuild in package.json image

Like this and it will work fine. Lmk if it works out.

bracki commented 3 months ago

Switched to Node 20 from 18. Now it works. 🎉