sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Rebuilt Sharp with SHARP_FORCE_GLOBAL_LIBVIPS embeds absolute paths - how to make it portable for Electron packaging

Open Ouy2dev opened this issue 2 months ago • 1 comments

Question about an existing feature

What are you trying to achieve?

I'm trying to rebuild Sharp from source in an Electron application to support HEIC/HEVC image conversion using Homebrew's libvips (which has full HEVC decoder support).

The rebuild process works perfectly in development:

  • Sharp successfully converts HEIC images with HEVC compression
  • All functionality works as expected locally

However, after packaging the Electron app with electron-builder, Sharp fails because the rebuilt sharp-darwin-arm64.node contains hardcoded absolute paths to my build machine's Homebrew libraries (e.g., /opt/homebrew/opt/vips/lib/libvips.42.dylib), which don't exist on end-user machines.

Goal: Make the rebuilt Sharp portable by using relative paths (@rpath) instead of absolute paths, so the packaged Electron app can run on any macOS machine without requiring Homebrew to be installed.

When you searched for similar issues, what did you find that might be related?

I found several related issues:

  • Issues about rebuilding Sharp with custom libvips installations
  • Discussions about using SHARP_FORCE_GLOBAL_LIBVIPS=1 environment variable
  • General packaging issues with native modules in Electron

However, I couldn't find specific guidance on how to make the rebuilt Sharp use relative paths (@rpath) for dynamic library dependencies when packaging for distribution.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question

Environment:

  • macOS: 14.x (Apple Silicon M1)
  • Node.js: 22.21.0
  • Electron: 33.x
  • Sharp: 0.34.5
  • libvips: 8.17.3 (via Homebrew)
  • electron-builder: 25.1.8

Ouy2dev avatar Dec 09 '25 07:12 Ouy2dev

Did you see the script thats create the prebuilt binaries provided by sharp, in particular (recursive) use of install_name_tool?

https://github.com/lovell/sharp-libvips/blob/main/build/posix.sh#L427

Please remember there may be patent royalties due when distributing an application able to en/decode HEVC.

lovell avatar Dec 09 '25 09:12 lovell