electron-forge does not work on the WSL by default. This is expected since WSL can't run GUI applications on linux.
When using "vanilla" electron through the WSL manually installing the win32 version of electron fixes this issue. (see here)
Unfortunatly, this approach results in this error when using electron-forge
(electron:325): Gtk-WARNING **: cannot open display:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `electron-forge start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
It seems like the reinstalling of electron had no effect - even though im unsure why this is happening.
Instructions to reproduce:
electron-forge init test ; cd testnpm install && npm uninstall electron && export npm_config_platform=win32 && npm install electron && unset npm_config_platformnpm startI think this is expected behavior. If I remember correctly, WSL is effectively a virtualized Linux.
Yes - But there has to be a way to fix this (especially because there is a workaround when using vanilla electron which for some reason doesnt work here..)
This is Forge v5, right? Try uninstalling both electron and electron-prebuilt-compile.
I don't know whether we'd want to add a bunch of detection code just for WSL users. I don't even know if Forge is the right place to have that code.
Electron tests typically need an X11 server running, it looks like you don't have one - try running this with vcxsrv running and configured correctly
I've talked to some Electron devs who are more familiar with the Windows environment than I am, and the consensus is that you should be using WSL + Forge just to package for Linux (i.e., .deb, .rpm, Snap). For the development cycle, you should be using Windows proper (e.g., CMD/Powershell for CLI).
Ok, thanks for the feedback - even though I disagree. Linux has, by far, the more advanced ecosystem for software development. I would much rather use it than having to use a crappy OS like windows for development.
As Paul said, you'll need an X server running if you want to run an Electron app under WSL without a lot of headaches (which uses the Linux target, because you're technically running under Linux).
Feel free to try to figure out how to get a Forge project with a Windows target working (I would suggest using the v6 beta instead of v5, if only because we're not adding any new features to v5), and if it ends up being a relatively clean solution (unlike that fourth bullet point in your repro instructions), you should definitely file an issue/PR in the appropriate project.
Most helpful comment
As Paul said, you'll need an X server running if you want to run an Electron app under WSL without a lot of headaches (which uses the Linux target, because you're technically running under Linux).
Feel free to try to figure out how to get a Forge project with a Windows target working (I would suggest using the v6 beta instead of v5, if only because we're not adding any new features to v5), and if it ends up being a relatively clean solution (unlike that fourth bullet point in your repro instructions), you should definitely file an issue/PR in the appropriate project.