Cross platform support Sharp Node.JS

Viewed 5

I was having trouble using Sharp (npm i sharp) in two different computers, a Mac and a Linux.

I was getting the following error:

Error: 
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp-darwin-x64.node'

Possible solutions:
- Install with verbose logging and look for errors: "npm install --ignore-scripts=false --foreground-scripts --verbose sharp"
- Install for the current darwin-x64 runtime: "npm install --platform=darwin --arch=x64 sharp"
- Consult the installation documentation: https://sharp.pixelplumbing.com/install
    at Object.<anonymous> 

The cross platform topic in the official documentation (https://sharp.pixelplumbing.com/install#cross-platform) didn't help. Tried to follow what they suggested, but kept getting the same error.

1 Answers

What did I do to solve it?

The Sharp package was originally installed in the Linux computer. So, to add support to MacOS:

  1. In the MacOS computer, ran npm remove sharp
  2. In the MacOS computer, ran npm i sharp

That left me with 10 changed files: 5 of them removing Linux support, 5 of them adding MacOS support. I then discarded the removal of the 5 Linux files, and kept the addition of the 5 MacOS files, as the following image:

enter image description here

This way, I ended with support in the two platforms. Hope this helps someone who needs it.

Related