Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run electron-forge on the Linux Subsystem for Windows (WSL) #548

Closed
NyxCode opened this issue Aug 9, 2018 · 8 comments
Closed

Run electron-forge on the Linux Subsystem for Windows (WSL) #548

NyxCode opened this issue Aug 9, 2018 · 8 comments
Labels

Comments

@NyxCode
Copy link

NyxCode commented Aug 9, 2018

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:

  • Install the Debian WSL
  • Install electron-forge in wsl
  • electron-forge init test ; cd test
  • npm install && npm uninstall electron && export npm_config_platform=win32 && npm install electron && unset npm_config_platform
  • npm start
@malept
Copy link
Member

malept commented Aug 9, 2018

I think this is expected behavior. If I remember correctly, WSL is effectively a virtualized Linux.

@NyxCode
Copy link
Author

NyxCode commented Aug 9, 2018

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..)

@malept
Copy link
Member

malept commented Aug 9, 2018

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.

@anaisbetts
Copy link
Contributor

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

@malept malept added the question label Aug 9, 2018
@malept
Copy link
Member

malept commented Aug 9, 2018

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).

@malept malept closed this as completed Aug 9, 2018
@NyxCode
Copy link
Author

NyxCode commented Aug 9, 2018

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.

@malept
Copy link
Member

malept commented Aug 9, 2018

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.

@JasonPierce
Copy link

JasonPierce commented Feb 2, 2023

I've been developing Electron apps from within WSL2 (Ubuntu 22.04) for some time. The following steps work with electron-forge (and other Electron frameworks):

  1. [Ubuntu] install libs: sudo apt update && sudo apt install libnss3-dev libgdk-pixbuf2.0-dev libgtk-3-dev libxss-dev libasound2
  2. [Windows] install windows manager for Ubuntu: VcXsrv Windows X Server
  3. [Ubuntu] Configure Ubuntu to use VcXsrv by pasting the below at the bottom of ~/.zshrc (or bashrc, etc)
    export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
    export LIBGL_ALWAYS_INDIRECT=true
  4. Download the attached zip file (VcXSrv_Config-Electron_WSL2.zip) and extract the VcXSrv config file to the root of your Electron app (e.g., where your package.json resides)
  5. [Windows] Start VcXSrv using the config: from within Windows Explorer, double-click your config.xlaunch
  6. [Ubuntu] Start your Electron app (e.g., npm start)

NOTE: Step 5 will need to be done prior to any development session in Electron. Be sure to close VcXSrv after the development session is complete: right-click VcXSrv icon in the Windows Tray and select Exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants