Demo app to reproduce bug with packaging Sharp with Electron.
These steps were performed on Ubuntu 20.04.2, running in WSL2 on Windows 10.
- Generated using steps from https://www.electronforge.io/templates/typescript-+-webpack-template
- Installed
sharp
and type defs with following args (npm v6):
npm install sharp --build-from-source --unsafe-perm
- Updated
webpack.renderer.config.js
to add sharp toexternals
fields - Updated
src/renderer.ts
script to call Sharp - Updated
src/index.ts
to setnodeIntegration
totrue
andcontextIsolation
tofalse
When the Electron app is packaged for distribution, Sharp is not bundled with it.
From the application root, run:
npm start
The basic Electron Forge demo window will open. The console should contain no errors, and show the sharp
object definition being printed out.
From the application root, run:
npm run package
Once completed, run the generated executable. E.g. on Linux:
out/electron-sharp-demo-linux-x64/electron-sharp-demo
The basic Electron Forge demo window will open. This time, the console will contain the following error:
Uncaught Error: Cannot find module 'sharp'