快乐随行

导航

npm 及 yarn 代理设置及更换为国内下载源

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.npmjs.org/

yarn config set registry https://registry.npmjs.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

6.YARN设置代理:

yarn config set proxy <http_proxy>
yarn config set https-proxy <https_proxy>

7. YARN删除代理:

yarn config delete proxy  
yarn config delete https-proxy

posted on 2020-08-04 17:13  快乐随行  阅读(6689)  评论(0编辑  收藏  举报