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
https://www.cnblogs.com/jddreams/p/13434482.html