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: 
I found an easier solution when building from MacOS or Windows, I use a Makefile with SAM and provide linux as a target for the NPM install.

**template.yaml**

```
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: mycode/
      Handler: handler.handler
      Runtime: nodejs12.x
      MemorySize: 512
      Timeout: 5
      Role: !GetAtt EdgeLambdaRole.Arn
    Metadata:
        BuildMethod: makefile

```

**mycode/makefile**

```
build-MyFunction:
    cp *.js $(ARTIFACTS_DIR)
    cp package.json $(ARTIFACTS_DIR)
    cp package-lock.json $(ARTIFACTS_DIR)
    cd $(ARTIFACTS_DIR) && npm install --production --arch=x64 --platform=linux

```

*Make sure you use TABS in your makefile*
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.