Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using sharp on serverless offline always fails

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:

  • serverless offline
  • node12 (x64)
  • m1 chip (arm64)
  • Serverless esbuild plugin used

solutions tried:

  • delete and reinstall node modules
  • install vips with brew
  • https://github.com/lovell/sharp/issues/2460#issuecomment-739110356
  • https://github.com/lovell/sharp/issues/2588#issuecomment-783254806
like image 486
mamadou jallow Avatar asked May 25 '26 10:05

mamadou jallow


1 Answers

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
like image 80
Sayef Reyadh Avatar answered May 28 '26 02:05

Sayef Reyadh