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\sharpbuild\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\sharpbuild\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.
and for posterity - using node-gyp to install:
https://gist.github.com/andrewrt/fa3a08f7346ef2c023565ed07c1fecd7
Install electron forge:
npm install -g [email protected]
Create electron app & run:
andrew@ANDREWT0C72 MINGW64 ~/code/js/electron
$ electron-forge init test-sharp --template=react
andrew@ANDREWT0C72 MINGW64 ~/code/js/electron
$ cd test-sharp/
andrew@ANDREWT0C72 MINGW64 ~/code/js/electron/test-sharp (master)
$ electron-forge start
(see electron working - app says "Welcome to React!")
Install sharp:
andrew@ANDREWT0C72 MINGW64 ~/code/js/electron/test-sharp (master)
$ npm i --save sharp
> [email protected] install C:\Users\andrew\code\js\electron\test-sharp\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\test-sharp\node_modules\sharp\build\Release
info sharp Copying DLLs from C:\Users\andrew\code\js\electron\test-sharp\node_modules\sharp\vendor\lib to C:\Users\andrew\code\js\electron\test-sharp\node_modules\sharp\build\Release
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\electron-installer-flatpak):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin,linux","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\electron-installer-debian):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin,linux","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\macos-alias):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\electron-installer-redhat):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin,linux","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\appdmg):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fs-xattr):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"!win32","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ [email protected]
added 28 packages from 88 contributors and audited 10505 packages in 24.831s
found 20 vulnerabilities (5 low, 8 moderate, 6 high, 1 critical)
run `npm audit fix` to fix them, or `npm audit` for details
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 start
Now the app won't launch
Did you see #1810, which suggests electron-forge v6 is required? The use of electron-rebuild will definitely be required but I think electron-forge runs this for you.
thanks @lovell - will give it a shot
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
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)
An unhandled rejection has occurred inside Forge:
[Error: EISDIR: illegal operation on a directory, read] {
errno: -4068,
code: 'EISDIR',
syscall: 'read'
}
Electron Forge was terminated. Location:
{}
$ HOME=~/.electron-gyp node-gyp rebuild --target=7.1.0 --arch=x64 --dist-url=https://electronjs.org/headers
tried npm-check as well - showing no issues aside from suggesting to go back to the latest electron (7.1.0)
If you didn't see it, setting the DEBUG environment variable as instructed in https://github.com/electron-userland/electron-forge/blob/master/SUPPORT.md#troubleshooting might help.
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...
Got it working @lovell -
@shadeofgod provided the answer here: https://github.com/JoshuaWise/better-sqlite3/issues/126
by adding
// webpack config
{
// ...
externals: {
'better-sqlite3': 'commonjs better-sqlite3',
},
}
I've updated the sharp test repo to see it "in action" as well
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
plugins: [
new CopyPlugin([
{
from: './node_modules/sharp/',
to: 'main_window/node_modules/sharp/', // still under node_modules directory so it could find this module
// ignore: [...]
},
]),
]
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...
@andrewrt any update on this? I'm facing the same issue
Most helpful comment
@andrewrt any update on this? I'm facing the same issue