Closed andrewrt closed 2 years ago
Issue logged w/ the sharp author - assumed electron-forge v6 might fix, to no avail (https://github.com/lovell/sharp/issues/1951)
as noted in https://github.com/lovell/sharp/issues/1951 - got it working. It was an issue with webpack config - so adding "externals" fixed
A quick heads up - the above gets it working in dev mode, but when packaging - the sharp module gets left out in the packaged app.
Trying to figure out how @shadeofgod 's CopyPlugin
example would work in the electron-forge flow.
if I add the copy plugin to my webpack.renderer.config.js
as so - I still get sharp not found:
const rules = require('./webpack.rules');
const CopyPlugin = require('copy-webpack-plugin');
rules.push({
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
});
module.exports = {
// Put your normal webpack config below here
module: {
rules ,
},
externals: {
"sharp": 'commonjs sharp',
},
plugins: [
new CopyPlugin([
{
from: './node_modules/sharp/',
to: './output/node_modules/sharp/', // still under node_modules directory so it could find this module
// ignore: [...]
},
]),
]
};
output from the console:
Uncaught Error: Cannot find module 'sharp'
Require stack:
- C:\Users\andrew\code\js\electron\sharp-ef6\out\test-ef6-win32-x64\resources\app\.webpack\renderer\main_window\index.html
at Module._resolveFilename (internal/modules/cjs/loader.js:717)
at Function../lib/common/reset-search-paths.ts.Module._resolveFilename (reset-search-paths.ts:40)
at Module._load (internal/modules/cjs/loader.js:622)
at Module._load (electron/js2c/asar.js:717)
at Function.Module._load (electron/js2c/asar.js:717)
at Module.require (internal/modules/cjs/loader.js:775)
at require (internal/modules/cjs/helpers.js:68)
at Object.<anonymous> (external "sharp":1)
at n (bootstrap:19)
at Module.<anonymous> (app.js:33)
I am facing the same problem.
Woudl be great if anyone had an idea on how to fix this.
@mauricedoepke any updates on this? I am facing the same issue...
@aperkaz Even after lots of research and fiddling with the webpack config I was not able to make sharp work with electron-forge.
Some alternative solutions are:
But as even the wasm solutions are much slower then sharp (https://libvips.github.io/libvips/2020/09/01/libvips-for-webassembly.html) I switched to https://www.electron.build/ instead With electron build I was able to get sharp working. If you use other native modules then sharp, you need to make sure though, to exclude sharp js from being rebuild by electron-rebuild. This will mess up sharp and you have to reinstall it.
For this reason I have this script in my package.json:
"rebuild": "yarn add sharp && copyfiles sqlite3.tar.gz ./node_modules/better-sqlite3/deps && electron-rebuild -o better-sqlite3",
Here I install a fresh version of sharp to fix possible corruptions of the installation and then only rebuild sqlite with electron rebuild to not corrupt sharp again.
This is a bit hacky, but works.
If you have detail questions, just write me via my email in my profile.
@mauricedoepke I managed to get it to work (on the main process), by using babel and modifying the webpack configs.
Repo with working example: https://github.com/aperkaz/electron-forge-sharp
I could not make it work from a render process, so any PR is welcome 🙂
@vercel/webpack-asset-relocator-loader
will not support every native node module and the majority of maintainers are not going to want to or be able to support the way it works.
For this reason I've created this plugin that helps include native modules during packaging.
You pass it a list of modules and it searches for all dependencies and includes them in node_modules
in the packaged app.
I'm having this in both my dev environment and packaged app with forge, it happens when I use push events to IPCRenderer. Any fix to this?
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:
@fourwadu why are you posting this here? It appears completely unrelated to this issue.
Duplicate of #1250
TLDR:
electron-forge@5.2.4
+sharp
image module work well in OSX. sharp image module stand-alone works in Windows 10 (git-bash
), butconst sharp = require('sharp')
causes the app (renderer) to not load / just show white).For
electron-forge@6.0.0-beta.45
: In electron-forge 6.x when running, I get an error now - but it doesn't give enough info for me to be able to debug further (see below) the error doesn't tell me what is doing the "syscall" / "read" so I'm hoping someone might have some further ideas on how to get more info on the failed import/require.Native Module Rebuild Attempts:
I have tried using
electron-rebuild
andnode-gyp
to force rebuild sharp for electron, but that changed nothing. Both show that sharp was successfully added / rebuilt. Using node-gyp to install: https://gist.github.com/andrewrt/fa3a08f7346ef2c023565ed07c1fecd7Here's a simple repo to reproduce the problem: https://github.com/andrewrt/ef6-sharp
*Console output when you run
electron-forge
with the environment variable `DEBUG=electron-forge:`. (Instructions on how to do so here). Please include the stack trace if one exists.**What command line arguments are you passing?
What does your
config.forge
data inpackage.json
look like?see repo for package/config and reproducing the issue - https://github.com/andrewrt/ef6-sharp/blob/master/src/app.js
Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem. Using
electron-forge init
is a good starting point, if that is not the source of your problem.Simple project to reproduce: https://github.com/andrewrt/ef6-sharp/blob/master/src/app.js