Question: When attempting to run sharp inside an AWS Lambda function, I keep getting the following error:

> 
> darwin-x64' binaries cannot be used on the 'linux-x64' platform.
>  Please remove the 'node\_modules/sharp/vendor' directory and run 'npm
>  install'
> 
> 
> 

I deploy my serverless applications with Serverless Framework from my MacBook Pro. How do I fix this problem?

Answer: 
Kudos to [stdunbar](https://stackoverflow.com/users/2933977/stdunbar) for steering me in the right direction. 

When installing sharp on MacOS via NPM the normal way (i.e.: `npm i sharp --save`), the installer automatically adds binaries for OS X. But AWS lambda functions run on Linux 2 machines with x64 processors and this is why we get this error.

**To fix you must first uninstall sharp completely and then run:**

```
npm install --arch=x64 --platform=linux sharp

```

**Note:**

version 0.25 no longer works with the target flag. This used to work:

```
npm install --arch=x64 --platform=linux --target=10.15.0 sharp

```

Then deploy as usual from Serverless Framework with `sls deploy`

**Side Note:**

Sharp is EXTREMELY FAST!!! Before using sharp, I was using another image resizing utility named Jimp. It did the job, but was quite slow. To prevent timeout errors, I had to increase the memory size from 128 to 512 and the timeout from 5 seconds to 30 seconds just to handle a typical 1 megabyte image.

Here is a comparison between the two for resizing a 1.2Mb picture down to 600x400 using the same configuration:

> 
> Jimp -> used 512Mb of memory and AWS billed me for 14300 ms. 
> 
> 
> Sharp -> used 132 MB of memory and AWS billed me for 800 ms.
> 
> 
> **That's more than 14x faster than Jimp!!!**
> 
> 
>
For anyone stumbling upon this post now. I've accomplished this by copying my `package.json` file into an [AWS Cloud9 IDE](https://aws.amazon.com/cloud9/) and simply running `npm install`. From there, just download the `node_modules/` folder.