When I invoke any function in my serverless application I get an error as below. However, directly installing sharp give me no errors. also, when I run the tests sharp works perfectly.
Missing module": /build/Release/sharp-darwin-x64.node" exists in the node modules
Error:
Something went wrong installing the "sharp" module
Cannot find module '../build/Release/sharp-darwin-x64.node'
Require stack:
- /.esbuild/.build/src/functions/function1/handler.js
System:
solutions tried:
According to the official documentation, try installing sharp.
npm install --arch=x64 --platform=darwin sharp
For AWS lambda deployment with Sharp module, the following worked for me when using serverless, esbuild and serverless-esbuild. Changed the serverless.yml file with the below configuration. It is basically telling esbuild to download sharp again with the following --arch=x64 --platform=linux considering your lambda uses x64 arch. Check serverless-esbuild packager and packagerOptions options for more understanding.
esbuild:
# keep existing configurations
external:
- sharp
packagerOptions:
scripts:
- npm install --arch=x64 --platform=linux sharp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With