Electron.NET でアプリを作成していて、electronize start
を実行したときにエラーが表示されたときに行った対処方法です。
環境
- Windows 10
- .NET Core 3.1
- Node.js v12.13.1
- npm 6.12.1
エラー内容
electronize start
を実行したとき、家では上手くいったのですが、会社で試すと以下のようなエラーが表示されてアプリケーションが起動しませんでした。
C:\Users\username\git\github\BlazorOnElectron\BlazorOnElectron\obj\Host\node_modules\electron\index.js:14
throw new Error('Electron failed to install correctly, please delete node_modules/electron and try installing again')
^
Error: Electron failed to install correctly, please delete node_modules/electron and try installing again
at getElectronPath (C:\Users\username\git\github\BlazorOnElectron\BlazorOnElectron\obj\Host\node_modules\electron\index.js:14:11)
at Object.<anonymous> (C:\Users\username\git\github\BlazorOnElectron\BlazorOnElectron\obj\Host\node_modules\electron\index.js:18:18)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (C:\Users\username\git\github\BlazorOnElectron\BlazorOnElectron\obj\Host\node_modules\electron\cli.js:3:16)
at Module._compile (internal/modules/cjs/loader.js:959:30)
node_modules/electron
を削除してもう一度インストールしろとあるものの解決せず。
また、ネットで検索してみると同じようなエラーが表示されたケースがそれなりに見つかるものの、どの対処方法でも解決しませんでした。
対処方法
かなりはまりましたが、家と会社で大きく違うのがプロキシ環境下かどうかなので、electron のプロキシ設定について調べてみると以下のページを見つけました。
ちなみに npm config のプロキシ設定は設定済みです。
結果として、以下の環境変数を設定することで解決しました。
(Node.js のバージョンが 10 以降かどうかで異なるようなので注意してください。)
set ELECTRON_GET_USE_PROXY=true
set GLOBAL_AGENT_HTTP_PROXY=http://proxyserver:port
set GLOBAL_AGENT_HTTPS_PROXY=http://proxyserver:port
プロキシサーバーのアドレスとポートは環境に応じて変更してください。