LoginSignup
14
9

More than 3 years have passed since last update.

Proxy環境下でElectron7系以降をnpm installするとENOTFOUND github.comエラーになるのを解消する

Posted at

この投稿で使用している言語、ライブラリのバージョン

  • Node.js v13.10.1
  • npm v6.14.2
  • Electron v8.0.3

困ったこと

Proxy環境下でElectron6系はnpm install出来ていたのに、

Electron7系にアップデートしてnpm installを実行するとgetaddrinfo ENOTFOUND github.comコケるという事象が発生しました。

$ git clone https://github.com/electron/electron-quick-start
$ cd electron-quick-start
$ cat package.json
{
  "name": "electron-quick-start",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "repository": "https://github.com/electron/electron-quick-start",
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "electron": "^8.0.3"
  }
}
$ npm install

> core-js@3.6.4 postinstall /Users/geekduck/Downloads/electron-quick-start/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"


> electron@8.0.3 postinstall /Users/geekduck/Downloads/electron-quick-start/node_modules/electron
> node install.js

(node:54108) UnhandledPromiseRejectionWarning: RequestError: getaddrinfo ENOTFOUND github.com
    at ClientRequest.<anonymous> (/Users/geekduck/Downloads/electron-quick-start/node_modules/got/source/request-as-event-emitter.js:178:14)
    at Object.onceWrapper (events.js:423:26)
    at ClientRequest.emit (events.js:328:22)
    at ClientRequest.EventEmitter.emit (domain.js:485:12)
    at ClientRequest.origin.emit (/Users/geekduck/Downloads/electron-quick-start/node_modules/@szmarczak/http-timer/source/index.js:37:11)
    at TLSSocket.socketErrorListener (_http_client.js:432:9)
    at TLSSocket.emit (events.js:316:20)
    at TLSSocket.EventEmitter.emit (domain.js:485:12)
    at emitErrorNT (internal/streams/destroy.js:84:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:54108) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:54108) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
added 86 packages from 96 contributors and audited 103 packages in 33.644s

2 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

解決方法

Electron7系以降では、環境変数http_proxyhttps_proxy見てくれなくなりました

Proxy環境下でElectron7系をインストールするには、以下の3つの環境変数の設定が必要です。

ELECTRON_GET_USE_PROXY ... Electron本体のダウンロード時にプロキシを使うかどうか
GLOBAL_AGENT_HTTP_PROXY ... Electron本体のダウンロード時に使用するhttpプロキシ
GLOBAL_AGENT_HTTPS_PROXY ... Electron本体のダウンロード時に使用するhttpsプロキシ

bash系の場合

.bashrc
export ELECTRON_GET_USE_PROXY=1 # 値は1でもtrueでもなんでも良い
export GLOBAL_AGENT_HTTP_PROXY=http://proxy.example.com:8080
export GLOBAL_AGENT_HTTPS_PROXY=https://proxy.example.com:8080

fish系の場合

.fishrc
set -x ELECTRON_GET_USE_PROXY 1 # 値は1でもtrueでもなんでも良い
set -x GLOBAL_AGENT_HTTP_PROXY http://proxy.example.com:8080
set -x GLOBAL_AGENT_HTTPS_PROXY https://proxy.example.com:8080

参考
インストール#プロキシ
global-agentのプロキシ指定方法

14
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
9