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: 
If you use [serverless](https://www.serverless.com) along with [serverless-webpack](https://www.serverless.com/plugins/serverless-webpack), you must use this [custom-config](https://www.serverless.com/plugins/serverless-webpack#custom-scripts) in your `serverless.yml` file:

```yaml
custom:
  # ...
  webpack:
    # ...
    packagerOptions:
      scripts:
        - npm install --arch=x64 --platform=linux sharp

```
If you use SAM you could build your function inside an AWS Lambda-like Linux Docker container:

```
sam build -u

```