Proxy環境でElectronインストールしようとしたら隠れた罠があったんです


何が起こったか?

会社でElectron使おうと思って、yarn installしたのにバイナリが降ってこなかった。
Quick Startも、Electronのインストールだけできなくて、なんぞこれってなった。
ちなみに家だと、どちらもすんなり動いた。

Proxyじゃん...

家ならセーフ会社でアウトって、完全にProxyのせいじゃん

$ npm -g config set proxy http://proxy:port
$ npm -g config set https-proxy http://proxy:port

Proxy設定は、これまでに行っていたが念の為もう一度設定してみる。

ダメです。
Electronだけインストールできない。
ただnode_modules見に行くと、

.
├── LICENSE
├── README.md
├── cli.js
├── dist ★これがない
├── electron.d.ts
├── index.js
├── install.js
├── node_modules
├── package.json
└── path.txt

こんな感じ
distディレクトリだけない

公式ドキュメント

ちゃんと読んだことなかったけど、Proxyについて書いてくれていた。

If you need to use an HTTP proxy, you need to set the ELECTRON_GET_USE_PROXY variable to any value, plus additional environment variables depending on your host system's Node version:

Node 10 and above
Before Node 10

このELECTRON_GET_USE_PROXYが、やっかい というか使っている例をそんなに見つけられなかった。

しかもyou need to set the ELECTRON_GET_USE_PROXY variable to any value
これ以外に使い方みたいなのが書いてない

使用例ありました

export ELECTRON_GET_USE_PROXY=true // to activate proxy for electron/get module
export GLOBAL_AGENT_HTTPS_PROXY=my_proxy to configure global agent proxy

なるほど
実際使うのはWindows環境だったので

windows
SET ELECTRON_GET_USE_PROXY=true 
SET GLOBAL_AGENT_HTTPS_PROXY=http://proxy:port
Linux
export ELECTRON_GET_USE_PROXY=true
export GLOBAL_AGENT_HTTPS_PROXY=http://proxy:port

としてからインストールするとすんなり入った。

感想

ググるとnpm config set proxyで解決するケースが大半なんで過信してたけど、ELECTRON_GET_USE_PROXYは罠過ぎた。

参考サイト