INSTALL Electron ONLY ON WINDOWS in case of work via Windows Subsystem for Linux (WSL). It has troubles with starting if you install it on Linux side.
On Ubuntu under WSL you have to install some dependencies:
sudo apt update
sudo apt install \
libnss3 \
libnss3-dev \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libgtk-3-0 \
libgtk-3-dev \
libgbm1 \
libasound2 \
libgdk-pixbuf2.0-dev \
libxss-dev \
libgconf-2-4
Also you might see this error:
ERROR:bus.cc(407) Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
For my case, it was caused by the fact that the service was not started.
sudo service dbus start
"Failed to connect to the bus: Failed to connect to socket" "Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")" "/node_modules/electron/dist/electron exited with signal SIGTRAP" (one of reasons)
export DISPLAY=$(ip route list default | awk '{print $3}'):0
export LIBGL_ALWAYS_INDIRECT=1
export LIBGL_ALWAYS_SOFTWARE=true
USER_ID=$(id -u)
USER_NAME=$(id -un)
USER_GROUP=$(id -gn)
XDG_RUNTIME_DIR=/run/user/$USER_ID
DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus
#echo "Check if $XDG_RUNTIME_DIR exists"
#if [ -d $XDG_RUNTIME_DIR ]
#then
echo "Create XDG runtime directory"
sudo mkdir -p $XDG_RUNTIME_DIR
echo "Set $USER_NAME:$USER_GROUP as owner"
sudo chmod 700 $XDG_RUNTIME_DIR
sudo chown $USER_NAME:$USER_GROUP $XDG_RUNTIME_DIR
#fi
echo "Specify dbus daemon for address $DBUS_SESSION_BUS_ADDRESS"
dbus-daemon --session --address=$DBUS_SESSION_BUS_ADDRESS --nofork --nopidfile --syslog-only &
Also see this guide about Electron on WSL2:
- https://gist.github.com/caseywatts/9700b402b6b51d1d6af9f0b206739770
- https://www.beekeeperstudio.io/blog/building-electron-windows-ubuntu-wsl2#setting-up-an-electron-friendly-wsl-2-environment
- https://stackoverflow.com/questions/61110603/how-to-set-up-working-x11-forwarding-on-wsl2
- microsoft/WSL#7915
- https://stackoverflow.com/questions/73008985/sigtrap-when-starting-electron-on-wsl2 */