Sharp: XXX binaries cannot be used on the 'linux-x64' platform.

Created on 15 Nov 2018  路  5Comments  路  Source: lovell/sharp

Hi,
I was using sharp for an AWS Lambda function (v0.18.0) and it was working very well. I want to update to the last version (v0.21), however, I'm now having an issue:

  • 'darwin-x64' binaries cannot be used on the 'linux-x64' platform. (npm install done on mac)
  • 'win-x64' binaries cannot be used on the 'linux-x64' platform. (npm install done on win10)
    These errors

It looks like there is a problem with libvips:

"stackTrace": [
    "Object.<anonymous> (/var/task/node_modules/sharp/lib/constructor.js:9:22)",
    "Module._compile (module.js:570:32)",
    "Object.Module._extensions..js (module.js:579:10)",
    "Module.load (module.js:487:32)",
    "tryModuleLoad (module.js:446:12)",
    "Function.Module._load (module.js:438:3)",
    "Module.require (module.js:497:17)",
    "require (internal/module.js:20:19)",
    "Object.<anonymous> (/var/task/node_modules/sharp/lib/index.js:3:15)"
  ]

CloudWatch logs:

module initialization error: Error
    at Object.hasVendoredLibvips (/var/task/node_modules/sharp/lib/libvips.js:61:13)
    at Object.<anonymous> (/var/task/node_modules/sharp/lib/constructor.js:9:22)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/var/task/node_modules/sharp/lib/index.js:3:15)

I don't really understand your documentation
Do I need to install Docker, create a linux container and then do npm install?

question

Most helpful comment

Commit dcd6830 adds a Docker-less method to the docs.

rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux --target=8.10.0 sharp

http://sharp.pixelplumbing.com/en/latest/install/#aws-lambda

All 5 comments

Hello, AWS Lambda uses 64-bit Linux and you'll need to ensure npm install is run on the same platform to populate node_modules with the correct files.

The Docker command shown at http://sharp.pixelplumbing.com/en/stable/install/#aws-lambda allows you to run npm install inside a Linux container that closely matches the AWS Lambda runtime.

I couldn't run the cmd in your doc so I pulled ubuntu image (Docker), install npm and run npm install. All good now. Thank you for your reply though, appreciate it.

Commit dcd6830 adds a Docker-less method to the docs.

rm -rf node_modules/sharp
npm install --arch=x64 --platform=linux --target=8.10.0 sharp

http://sharp.pixelplumbing.com/en/latest/install/#aws-lambda

How does one do this with Yarn?

I've tried yarn add --arch=x64 --platform=linux --target=10.16.0 sharp but nothing is being installed into node_modules

you can try this:

download the latest release binaries from https://github.com/lovell/sharp/releases and manually copy sharp.node into node_modules/sharp/build/Release, then do serverless deploy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

henbenla picture henbenla  路  3Comments

paulieo10 picture paulieo10  路  3Comments

zilions picture zilions  路  3Comments

OleVik picture OleVik  路  3Comments

kachurovskiy picture kachurovskiy  路  3Comments