Repository navigation
Description
Problem:
I'm trying to use sharp w/ electron.
Everything (sharp+electron) is working in OSX.
On Windows (using gitbash), I'm able to use sharp globally installed with a simple node.js test, but not in electron.
As soon as I uncomment
const sharp = require('sharp');
the app white-screens and doesn't load (no further errors / hints / direction).
Install
Sharp installs w/o errors:
verbose output from fresh install: link
non-verbose:
$ npm i --save sharp
[email protected] install C:\Users\andrew\code\js\electron\spec-electron\node_modules\sharp
(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.8.1/libvips-8.8.1-win32-x64.tar.gz
info sharp Creating C:\Users\andrew\code\js\electron\spec-electron\node_modules\sharp\build\Release
info sharp Copying DLLs from C:\Users\andrew\code\js\electron\spec-electron\node_modules\sharp\vendor\lib to C:\Users\andrew\code\js\electron\spec-electron\node_modules\sharp\build\Release
- [email protected]
added 13 packages from 65 contributors and audited 14365 packages in 21.978s
found 20 vulnerabilities (5 low, 8 moderate, 6 high, 1 critical)
runnpm audit fixto fix them, ornpm auditfor details
Environment:
$ npx envinfo --binaries --languages --system -- utilities
npx: installed 1 in 1.828sSystem:
OS: Windows 10
CPU: (2) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Memory: 3.40 GB / 7.10 GB
Binaries:
Node: 12.4.0 - C:\Program Files\nodejs\node.EXE
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
Languages:
Bash: 4.4.23 - C:\Program Files\Git\usr\bin\bash.EXE
Perl: 5.26.2 - C:\Program Files\Git\usr\bin\perl.EXE
Python: 2.7.17 - C:\Python27\python.EXE
Similar question:
This is very similar to #1846, but the suggested solutions aren't working:
Attempting solution from @lovell :
andrew@ANDREWT0C72 MINGW64 ~/code/js/electron/spec-electron (windows10)
$ ./node_modules/.bin/electron-rebuild
- Searching dependency tree
√ Rebuild Complete
but problem persists
Attempting solution from Mubaidr:
$ ./node_modules/.bin/electron-builder install-app-deps
• electron-builder version=22.1.0
• rebuilding native dependencies dependencies=@serialport/[email protected], [email protected] platform=win32 arch=x64
• install prebuilt binary name=@serialport/bindings version=8.0.4 platform=win32 arch=x64
• build native dependency from sources name=@serialport/bindings
version=8.0.4
platform=win32
arch=x64
reason=prebuild-install failed with error (run with env DEBUG=electron-builder to get more information)
error=prebuild-install info begin Prebuild-install version 5.3.3
prebuild-install WARN install prebuilt binaries enforced with --force!
prebuild-install WARN install prebuilt binaries may be out of date!
prebuild-install info looking for cached prebuild @ C:\Users\andrew\AppData\Roaming\npm-cache_prebuilds\afca11-bindings-v8.0.4-electron-v73-win32-x64.tar.gz
prebuild-install http request GET https://github.com/serialport/node-serialport/releases/download/v8.0.4/bindings-v8.0.4-electron-v73-win32-x64.tar.gz
prebuild-install http 404 https://github.com/serialport/node-serialport/releases/download/v8.0.4/bindings-v8.0.4-electron-v73-win32-x64.tar.gz
prebuild-install WARN install No prebuilt binaries found (target=6.1.4 runtime=electron arch=x64 libc= platform=win32)• install prebuilt binary name=sharp version=0.23.2 platform=win32 arch=x64
despite error on prebuild install for serialport - serial port still ends up working, uncommenting sharp still causes the app to fail to load.
I'm getting no errors out in the main console, nor in chrome tools console - so I'm grabbing at straws / looking for any ideas on what else I can try.
Activity
andrewrt commentedon Nov 6, 2019
and for posterity - using node-gyp to install:
https://gist.github.com/andrewrt/fa3a08f7346ef2c023565ed07c1fecd7
andrewrt commentedon Nov 6, 2019
Steps to reproduce:
Install electron forge:
npm install -g [email protected]Create electron app & run:
(see electron working - app says "Welcome to React!")
Install sharp:
Open src/app.jsx and add this after the 1st import:
const sharp = require('sharp');run:
andrew@ANDREWT0C72 MINGW64 ~/code/js/electron/test-sharp (master) $ electron-forge startNow the app won't launch
lovell commentedon Nov 6, 2019
Did you see #1810, which suggests
electron-forgev6 is required? The use ofelectron-rebuildwill definitely be required but I thinkelectron-forgeruns this for you.andrewrt commentedon Nov 6, 2019
thanks @lovell - will give it a shot
andrewrt commentedon Nov 7, 2019
Created a new electron-forge v6 project - added sharp, and run - crashes when adding require('sharp'); in app.js.
Project here: https://github.com/andrewrt/ef6-sharp
Steps & Tests:
npm i -g @electron-forge/clielectron-forge init ef6-sharp --template=webpacknpm i --save react react-domnpm i --save-dev babel-loader @babel/core @babel/preset-envconst sharp = require('sharp');(fails)Output:
$ HOME=~/.electron-gyp node-gyp rebuild --target=7.1.0 --arch=x64 --dist-url=https://electronjs.org/headersandrewrt commentedon Nov 7, 2019
tried npm-check as well - showing no issues aside from suggesting to go back to the latest electron (7.1.0)
lovell commentedon Nov 7, 2019
If you didn't see it, setting the
DEBUGenvironment variable as instructed in https://github.com/electron-userland/electron-forge/blob/master/SUPPORT.md#troubleshooting might help.andrewrt commentedon Nov 8, 2019
thanks @lovell - did that - didn't get much more - so as per the reference - seeing if the electron-forge crew might have some insight into how to get more info...
andrewrt commentedon Nov 8, 2019
Got it working @lovell -
@ShadeOfGod provided the answer here: WiseLibs/better-sqlite3#126
by adding
I've updated the sharp test repo to see it "in action" as well
andrewrt commentedon Nov 12, 2019
I'm going to re-open this one.
So the above workaround fixes the development environment for sharp+ef6, but the packaged product then leaves out sharp all together.
I couldn't figure out how to properly pack sharp back into the webpack environment as it's packaged by electron-packager.
I've tried updating the webpack rules to add in
but that led me to having to copy over all node_modules as i didn't know the correct path used by electron-forge + webpack.
Since other native plugins do seem to be working, I'm hoping this is something debuggable by sharp, but it's a bit beyond me to be able to provide much more detail...
emmekappa commentedon Aug 21, 2020
@andrewrt any update on this? I'm facing the same issue
Cosmin-Parvulescu commentedon Mar 4, 2021
Try adding sharp as an external in the webpack configuration for your electron main module.
In case this doesn't work by itself, using the
electron-rebuildNPM package and doing a manual run of./node_modules/.bin/electron-rebuildmight also help.aperkaz commentedon Apr 11, 2021
Building on what @andrewrt proposed, I managed to make it work in development and on packaged app, on the renderer process.
Workin example here: https://github.com/aperkaz/electron-forge-sharp
setup: add "sharp" and webpack setup for electron
patricktree commentedon Dec 25, 2021
I was not able to get sharp automatically packaged with the electron application (Windows x64, electron-forge 6.0.0-beta.61).
It would always show an error dialog when starting the packaged application.
However, I managed to get it to work - in development mode and the packaged windows app, in the main process - by doing the following:
webpack.main.config.js:node_modulesfolder in the.webpack/mainfolder.See this commit for the necessary changes: patricktree/file-explorer@e2bf09c.
When using a "pure" electron-forge setup, you might need to install
copy-webpack-plugin.It feels hacky to copy the node modules manually, but at least it works!
Cosmin-Parvulescu commentedon Jan 3, 2022
@pkerschbaum did this end up working for you all the way to production? I remember trying this and it wouldn't ultimately work on Android.
patricktree commentedon Jan 3, 2022
@Cosmin-Parvulescu This electron-forge project I am working on is only meant to run on Windows and Linux (and Mac OS eventually).
So far, I tested the packaged application on both Windows x64 and WSL 2 Ubuntu (WSLg), and I can confirm that my approach - copying
sharpand its dependencies manually - does work on these platforms.But I don't know if it would work on Android.