Sharp: Use Sharp with Electron V0.37

Created on 25 Mar 2016  路  2Comments  路  Source: lovell/sharp

I am trying to build a simple image resize/optimizer using Electron.atom.io on Windows 10.
The Electron documentation "Using Native Node Modules" at:

http://electron.atom.io/docs/v0.37.2/tutorial/using-native-node-modules/

Has the section "The Easy Way":

  npm install --save-dev electron-rebuild

  Every time you run 'npm install", run this
  .\node_modules\.bin\electron-rebuild.cmd

I installed electron-rebuild & Sharp without any errors or warnings.
Then executed the rebuild cmd without any npm errors or warnings.

When the javascript line: var jpg = require('sharp');
is executed, the following error is displayed (note truncated for brevity)

Error: A dynamic link library (DLL) initialization routine failed.
......\node_modules\sharp\build\Release\sharp.node
at Error(native)
at process.module.(anonymous function)as dlopen
at Object.Module._extensions..node(module.js450:18)
.........

Can Sharp work with Electron?
Or am I missing a step somewhere?

Thank you for any help, I would really like to use your package since it would fit very nicely into my needs.

Thanks,
Kris

question

Most helpful comment

Hi Lovell,

Thank you!! I got it working!!

It appears the issue was the electron-rebuild wasn't rebuilding the Sharp package properly. To get around that, using the 3rd method recommended by Electron documentation was needed. That was changing to the directory "node_modules\sharp" and then execute the node-gyp rebuild with the parameters of the target, arch, dist-url, AND adding the msvs_version allowed node-gyp to rebuild Sharp properly.

Thank you for providing the links. They were helpful in pointing me to the msvs_version parameter! By the way, using version 2015 does work. The suggestion of changing to an older release was not necessary. At least it worked for me.

Thank you, now I can start exploring your excellent package.
Kris

All 2 comments

Hello Kris, from your detailed description it looks like you've made very good progress towards getting this working. I've not tried this myself but am willing to attempt to help!

During the npm install process on Windows, sharp copies DLLs into the ...\node_modules\sharp\build\Release\ directory to become siblings of sharp.node. Do you see these?

My favourite tool to help debug this sort of problem is Dependency Walker. Point it at sharp.node and see what it says.

Have you seen the possibly related https://github.com/atom/electron/issues/4659 ? It includes a comment that only certain versions of Visual Studio might work.

Hi Lovell,

Thank you!! I got it working!!

It appears the issue was the electron-rebuild wasn't rebuilding the Sharp package properly. To get around that, using the 3rd method recommended by Electron documentation was needed. That was changing to the directory "node_modules\sharp" and then execute the node-gyp rebuild with the parameters of the target, arch, dist-url, AND adding the msvs_version allowed node-gyp to rebuild Sharp properly.

Thank you for providing the links. They were helpful in pointing me to the msvs_version parameter! By the way, using version 2015 does work. The suggestion of changing to an older release was not necessary. At least it worked for me.

Thank you, now I can start exploring your excellent package.
Kris

Was this page helpful?
0 / 5 - 0 ratings