Sharp: Electron: libvips-cpp.42.dylib image not found mac osx build

Created on 11 Jan 2017  路  10Comments  路  Source: lovell/sharp

ELECTRON_ASAR.js:173 Uncaught Error:
dlopen(/var/folders/rt/7f85090559l9jxmyt06cd_7w0000gn/T/.org.app.4Y18VM, 1): Library not loaded: @rpath/libvips-cpp.42.dylib
Referenced from: /var/folders/rt/7f85090559l9jxmyt06cd_7w0000gn/T/.org.app.4Y18VM
Reason: image not found

i get this when trying to build on electron (electron-builder).... not sure what image its looking for

question

Most helpful comment

it the seems the workaround for mac is to use Electron-builder and the asarUnpack option:
"build": { "asar": true, "appId": "myappid", "asarUnpack": [ "**/node_modules/sharp/**/*" ], "extraResources": [ "bg_mask.png" ], "mac": { "category": "app.beta.com", "icon": "assets/ico/mac_icon.icns" }, "win": { "iconUrl": "https://aurl.win_icon.ico" } },
this puts the sharp module outside asar... and it runs fine

All 10 comments

Hi Lovell,
yes I tried that page.
using electron 1.4.14
i tried rebuilding with the rebuild module: ./node_modules/.bin/electron-rebuild
same error..
I dont know if the issue is with the sharp module, node-gyp or electron-build/rebuild
but the problem only occurs on mac osx.. windows is fine (untested on linux)

Thanks for the update.

binding.js#L32 places pre-compiled binaries in the node_modules/sharp/vendor directory at npm install time.

binding.gyp#L141-L142 sets the runtime location for rpath so the compiled sharp.node shared library can find the pre-compiled binaries.

My best guess is that Electron on OS X is using non-standard locations. /var/folders/rt/7f85090559l9jxmyt06cd_7w0000gn/T/.org.app.4Y18VM looks very much non-standard :(

I'm having the same issue. I'm on a Mac, Node 6.9.1, NPM 3.10.8, sharp 0.17.1

My app works locally with sharp. After using electron-builder to generate the Mac dist of my app, when I run it on a machine without libvips installed through brew, I get.

Uncaught Error: dlopen(/Applications/test.app/Contents/Resources/app/node_modules/sharp/build/Release/sharp.node, 1): Library not loaded: /usr/local/opt/vips/lib/libvips-cpp.42.dylib
  Referenced from: /Applications/test.app/Contents/Resources/app/node_modules/sharp/build/Release/sharp.node
  Reason: image not found

Which makes sense.. I think, since libvips can't be found. I'd hoped the pre-built versions inside node_modules/sharp would cover it.

Before creating the dist, I made sure to use electron-rebuild, and it says Building module: sharp. I don't however see a /vendor folder inside the node_modules/sharp, but the Build/ folder looks right.

Compiling native modules is new to me, I know you don't explicitly support electron but would love any insight you have.

The appearance of /usr/local/opt suggests libvips might have previously been installed, or at least enough of it remains for pkg-config --modversion vips-cpp to think it has found it.

From v0.17.x onwards you'll see the node_modules/sharp/vendor directory created at npm install time, which hopefully is also the case for the electron npm install command I think you'll need to use with Electron.

node: 7.4.0 npm: 4.0.5
I was able to package the app fine after building inside the module directory:
./node_modules/.bin/electron-rebuild
HOME=~/.electron-gyp node-gyp rebuild --target=1.4.14 --arch=x64 --dist-url=https://atom.io/download/electron;

.. problem occurs with asar file option (asar: true)
it seems there are limitations with native modules and using calls like dlopen
http://electron.atom.io/docs/tutorial/application-packaging/

we need to use the asar option .. electron-builder claims to automate native module building
but its the same error above at runtime
could it be that the sharp module is misconfigured somehow..? is there a problem will modules that use node-gyp?

it the seems the workaround for mac is to use Electron-builder and the asarUnpack option:
"build": { "asar": true, "appId": "myappid", "asarUnpack": [ "**/node_modules/sharp/**/*" ], "extraResources": [ "bg_mask.png" ], "mac": { "category": "app.beta.com", "icon": "assets/ico/mac_icon.icns" }, "win": { "iconUrl": "https://aurl.win_icon.ico" } },
this puts the sharp module outside asar... and it runs fine

I ended up here because I have the same problem when running yarn dist i use electron-builder in my workflow.
adding

  "build": {
    "asar": true,
    "asarUnpack": ["**/node_modules/sharp/**/*"]
  }

to my package.json seems to solve the problem, yarn dist works, the application starts, and sharp works. But since I don't understand fully the implications, I am a bit unsure of using it in production

@lovell or @nphias is there any update?

Im still having this problem with Electron and unpacking the sharp module solution is not working any one has any other ideas ?
sharp": "^0.22.0",

@adhambadr You can try build the app without asar.

Was this page helpful?
0 / 5 - 0 ratings