1.出錯情況
npm安裝完成默認不走代理,所在如果公司內網是通過代理訪問外部網站,npm則會出現安裝插件失敗情況
2.設置代理
- 命令行窗口輸入:
npm config set proxy http://server:port
- 如果需要設https_proxy:
npm config set https-proxy http://server:port
- 設置了proxy就不需要設置https-proxy了。
- 如果需要代理用戶名和密碼
npm config set proxy http://username:password@server:port
npm confit set https-proxy http://username:password@server:port
3.取消代理
npm config delete proxy
npm config delete https-proxy
或者
npm config set proxy null
npm config set https-proxy null
4.修改源
國外源速度不穩定,可設置國內淘寶源。
- 查看現有源:
npm config get registry
- 設置淘寶源:
npm config set registry https://registry.npm.taobao.org
- 查看npm的設置
npm config list
或者
npm config ls -l
- 用新源更新一波package:
npm update
5.其他
- 在設置配置屬性時屬性值默認是被存儲於用戶配置文件中,如果加上--global,則被存儲在全局配置文件中
- 如果要查看npm的所有配置屬性(包括默認配置),可以使用npm config ls -l
- 如果要查看npm的各種配置的含義,可以使用npm help config
- 如果不能通過https fetch,可以使用npm config set strict-ssl false