junk0612's blog

junk0612 のブログです。ボードゲーム・カードゲーム、電源ゲーム、プログラミングが主なコンテンツ。

WSL で Electron を動かそうとした

やろうとしていたこと

JS の勉強に Electron でアプリを作ってみようと思って WSL 上で https://www.electronjs.org/ の Get started を動かそうとしてみた。

$ git clone https://github.com/electron/electron-quick-start
$ cd electron-quick-start
$ npm install && npm start

ところ、npm startで 以下のエラーが出た。

[455:0704/001142.352754:ERROR:ozone_platform_x11.cc(248)] Missing X server or $DISPLAY
[455:0704/001142.352824:ERROR:env.cc(226)] The platform failed to initialize.  Exiting.
/mnt/c/Users/nnuja/Documents/workspace/javascript/electron/electron-quick-start/node_modules/electron/dist/electron exited with signal SIGSEGV

今になって読んでみるとわかるけど、ディスプレイ用の設定がされていない。 とりあえずエラーメッセージをコピーしてググってみた。

解決策

見つかったのは WSL2でElectron開発する方法(VcXsrvなし) という Zenn の記事で、さらにその中で上記のメッセージに対応する内容が書かれていたのは Developing with WSL - Electron Forge だった。公式サイトにちゃんと情報が載っていた。

"If you are using Windows Subsystem for Linux (WSL), there are some quirks to running Electron apps." とのことで、npm install と npm start を win32 向けにしてみたらとりあえず動いた。

$ rm -r node_modules
$ npm install --platform=win32
$ npm start -- --platform=win32