6
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

proxy配下のnpm設定

Posted at

いつも忘れるので覚え書き。

社内環境によってnpmの実行がはじかれる場合。
まずは現在の設定を確認

$ npm config list

proxy設定

デフォルトでは環境変数のHTTP-PROXY(http-proxy)を参照。(設定がなければnull)
環境変数にproxy設定を入れるのが手っ取り早いが、今回はnpmだけproxy経由したいので、
npm configにproxy設定を追加。
※環境変数とnpm configに設定がある場合は、npm configが優先される

$ npm config set proxy http://PROXY.com:PORT

https-proxyも同様の設定

$ npm config set https-proxy http://PROXY.com:PORT

npm config に追加されていることを確認。

レジストリ設定

npm install 時に以下のようなエラーが発生したらregistry URLを変更

npm ERR! network tunneling socket could not be established, cause=7252:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:766:
npm ERR! network
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

registryのhttpshttpに変更

$ npm config set http://registry.npmjs.org/

以上でnpm installが利用可能になる。

proxyを削除する

proxy設定を削除する場合。以下をターミナルから実行。

$ npm config delete proxy
$ npm config delete https-proxy
$ npm config set https://registry.npmjs.org/  ←初期設定に戻す

proxy設定をON/OFFを繰り返すならBATにした方が良い。

6
13
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
6
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?