记 npm,git,bower 安装文件时的坑

首先交代故事的原由。vue2.0发布了,随之vue-cli脚手架工具也迎来了版本更新-2.4,
本觉得新特性会带来一些惊喜。带着愉悦的心情开始一个新项目vue init webpack project-name
弹出提示:vue

This will install Vue 2.x version of template.
For Vue 1.x use: Vue init webpack#1.0 vueproject

很人性化嘛,还提示版本初始化区别的命令。因而从新执行vue init webpack#1.0 project-name,始料未及的是:webpack

vue-cli · connect ETIMEDOUT 192.30.252.137:443

相似这种错误,大体是由于网络代理的缘由。接触git bash这款命令行工具好久了,虽然很强大,但也有一些命令是须要切换回cmd进行处理的。git

这里解释下为何不用2.4版本初始化项目。
其一,从vue1.0版本过渡到2.0须要时间,项目已经立项。
其二,vue2.0版本刚刚推出,本身以为还得等待一段时间才适合投入项目进行开发。github

这里来整理下目前存在的问题:web

  1. git base自身不够完善(win下),有时须要切回cmd模式;vue-cli

  2. 执行npm,git,bower等操做时,会时不时因网络代理而失败;npm

依次解决以上问题:bash

重装 git bash

  1. 卸载git bash服务器

  2. 从新安装git bash网络

  3. 安装时须要的设置:

    • 操做一

    • 操做二

    • 操做三

解决代理问题

有时候咱们在某些环境下(好比墙内或公司内网)可能不能正常使用 git/npm/bower/gem 等各类工具,那就使用代理吧。这里假定服务器代理地址为127.0.0.1,端口为1080

  1. 为 npm 设置代理

    npm config set proxy http://127.0.0.1:1080
    npm config set https-proxy http://127.0.0.1:1080

    注意不要遗漏 http:// ,不然可能安装某些package时可能会报:

    ERR! Error: Invalid protocol

    若是代理须要认证的话能够这样来设置:

    npm config set proxy http://username:password@server:port
    npm config set https-proxy http://username:pawword@server:port
  2. 为 git 设置代理

    • 第一种设置代理的方式

      git config --global http.proxy http://127.0.0.1:1080
      git config --global https.proxy http://127.0.0.1:1080

      因为代理上网,git 协议不能用,因此须要设置来用 https 协议替代:

      git config --global url."https://".insteadOf git://

      若是执行:

      git clone https://....

      报如下错误:

      error: server certificate verification failed.
      CAfile: /etc/ssl/certs/ca-certificates.crt
      CRLfile: none

      说明证书校验有问题,能够设置:

      git config --global http.sslverify false
    • 第二种方法是直接修改git的配置文件.gitconfig

      [http]
      proxy = http://10.24.48.191:808
      sslverify = false
      [https]
      proxy = http://10.24.48.191:808
      [url "https://"]
      insteadOf = git://
  3. 为 bower 设置代理

    bower 的安装和使用依赖于 npm 和 git,在完成前二者的代理设置后,有两种方法为 bower 设置代理。

    • 方法一直接修改 bower 的配置文件.bowerrc,若是没有能够添加:

      "proxy": "http://10.24.48.6:808",
      "https-proxy": "http://10.24.48.6:808"
    • 在系统变量里添加 HTTP_PROXY 和 HTTPS_PROXY。

执行vue init命令时,提示网络连接错误(win10环境下):

解决办法:设置`hosts`文件,路径为`C:\Windows\System32\drivers\etc`,删除有关github的字段便可。

代理设置参考连接;
git重装参考连接;

相关文章
相关标签/搜索