iT邦幫忙

2017 iT 邦幫忙鐵人賽
DAY 6
0
自我挑戰組

全端工程師的日常挑戰三十日系列 第 6

NPM Behind Proxy With Authentication

  • 分享至 

  • twitterImage
  •  

NPM Behind Proxy With Authentication

使用 npm 安裝套件時出現 ETIMEDOUT 的錯誤,錯誤訊息中有提示可能是 proxy 的問題
Error

YARN Behind Proxy With Authentication

yarn 安裝時 Error 是 ETIMEDOUT
Error

yarn 是使用 npm 設定

1. 設定

1-1. command line(Cmd.exe)

npm config set proxy http://UserName:password@proxyserver:proxyport
npm config set https-proxy http://UserName:password@proxyserver:proxyport
[with domain]
npm config set proxy http://domain%5CUserName:password@proxyserver:proxyport
npm config set https-proxy http://domain%5CUserName:password@proxyserver:proxyport
[實測後下面的設定非必要]
npm config set strict-ssl false
npm config set registry "http://registry.npmjs.org/"

1-2. 直接修改 npm config("C:\Users\username.npmrc")

proxy=http://UserName:password@proxyserver:proxyport
https_proxy= http://UserName:password@proxyserver:proxyport
[with domain]
proxy=http://UserName:password@proxyserver:proxyport
https_proxy= http://UserName:password@proxyserver:proxyport
[實測後下面的設定非必要]
strict-ssl=false
registry=http://registry.npmjs.org/

存檔後若未生效,請重啟 command line

2. 檢視設定結果

npm config get proxy
npm config get https_proxy

[實測後下面的設定非必要]

npm config get registry
npm config get strict-ssl

3. 單次安裝使用

npm --proxy http://UserName:password@proxyserver:proxyport install -g  packagename

4. 成功設定

成功

參考資料

  1. 官方說明(http-proxy)
  2. 官方說明(npm-config)
  3. stackoverflow

上一篇
建立可開機的 Windows Server 2016 安裝 USB
下一篇
網路輸入資料,按 tab 鍵,為什麼亂跳?!
系列文
全端工程師的日常挑戰三十日31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言