sharp: Sharp Module Installation Error: Library not loaded: @rpath/libvips-cpp.42.dylib

Hello,

I am really new at using Sharp and I was trying to install and run it for my app. I plan on using it to composite multiple images together.

The problem I am running into is after I do npm install sharp and in one of the files i have const sharp = require('sharp') run the app, I see:

`Something went wrong installing the “sharp” module dlopen(/Users/…/node_modules/sharp/build/Release/sharp.node, 1): Library not loaded: @rpath/libvips-cpp.42.dylib Referenced from: /Users/…/node_modules/sharp/build/Release/sharp.node Reason: Incompatible library version: sharp.node requires version 54.0.0 or later, but libvips-cpp.42.dylib provides version 51.0.0

I tried performing each of the steps but no luck. Also tried going here and installing this via homebrew https://libvips.github.io/libvips/install.html

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 19 (9 by maintainers)

Most upvoted comments

Ok I found the problem. It was that I have some dependencies installed which also have sharp as a dependency. So two different versions of sharp were in my node_modules directory. (FYI I’m using yarn workspaces)

$ yarn list sharp
yarn list v1.21.1
├─ app@1.0.0
│  └─ sharp@0.24.0
└─ sharp@0.23.4

In my case it was gatsby-plugin-manifest and @fiahfy/icns-convert which are both using sharp 0.23.4.

I was experiencing an unsupported image format error, with a regular PNG file that used to be working before.
Error: Input file contains unsupported image format (via gatsby-plugin-manifest)

Turns out there was some conflict between sharp and libvips version from brew (macOS).
What worked for me was forcing sharp to re-install with the bundled libvips.

brew uninstall vips
rm -rf node_modules
npm i

@MMA15 give it a try if on macOS, it may help.

Update: The problem is dependent of the import order of the library.

Does not work

const icnsConvert = require('@fiahfy/icns-convert');
const sharp = require('sharp');

Works

const sharp = require('sharp');
const icnsConvert = require('@fiahfy/icns-convert');

Example repository: https://github.com/sapkra/sharp-issue-2029