美文网首页
npm使用国内镜像解决安装连接失败错误

npm使用国内镜像解决安装连接失败错误

作者: 打工是不可能打工的1 | 来源:发表于2017-11-06 15:18 被阅读0次

一开始使用npm,想安装vue,结果执行npm install vue一直无法安装,报错如下:

live:api yuelin$ npm install vue
npm ERR! code ECONNRESET
npm ERR! errno ECONNRESET
npm ERR! network request to https://cnpmjs.oss-ap-southeast-1.aliyuncs.com/vue/-/vue-2.5.3.tgz failed, reason: socket hang up
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

网上一搜,原来也是国家高大的墙搞的鬼,所以要用npm要使用国内的镜像,有两种办法使用:
一、通过config命令

npm config set registry https://registry.npm.taobao.org 

如果运行npm info underscore出现

{
type: 'git',
     url: 'git://github.com/jashkenas/underscore.git' },
  versions: [
     '1.0.3',
     '1.0.4',
     '1.1.0',
  ],
  homepage: 'http://underscorejs.org',
  bugs: { url: 'https://github.com/jashkenas/underscore/issues' },
  license: 'MIT',
  keywords: [ 'util', 'functional', 'server', 'client', 'browser' ],
  main: 'underscore.js',
  version: '1.8.3',
  devDependencies: 
   { docco: '*',
     eslint: '0.6.x',
     karma: '~0.12.31',
     'karma-qunit': '~0.1.4',
     'qunit-cli': '~0.2.0',
     'uglify-js': '2.4.x' },
  scripts: 
   { test: 'npm run test-node && npm run lint',
     lint: 'eslint underscore.js test/*.js',
     'test-node': 'qunit-cli test/*.js',
     'test-browser': 'npm i karma-phantomjs-launcher && ./node_modules/karma/bin/karma start',
     build: 'uglifyjs underscore.js -c "evaluate=false" --comments "/    .*/" -m --source-map underscore-min.map -o underscore-min.js',
     doc: 'docco underscore.js' },
  files: 
   [ 'underscore.js',
     'underscore-min.js',
     'underscore-min.map',
     'LICENSE' ],
  gitHead: 'e4743ab712b8ab42ad4ccb48b155034d02394e4d',
  dist: 
   { shasum: '4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022',
     size: 34172,
     noattachment: false,
     tarball: 'http://r.cnpmjs.org/underscore/download/underscore-1.8.3.tgz' },
  directories: {},
  publish_time: 1427988774520 }

如果出现一处类似的json则表明成功配置了,但是这种配置方法好像只是暂时的,所以推荐使用方法二。
二、写进配置文件

vim ~/.npmrc

把内容替换成下面这句
registry = https://registry.npm.taobao.org
然后再运行npm install vue立马成功安装

相关文章

  • npm使用国内镜像解决安装连接失败错误

    一开始使用npm,想安装vue,结果执行npm install vue一直无法安装,报错如下: 网上一搜,原来也是...

  • Vue2.0项目入门 — 从环境搭建到运行

    环境安装 安装淘宝镜像大家都知道国内直接使用 npm 的官方镜像是非常慢的,这里推荐使用淘宝 NPM 镜像。下载...

  • vue2.0 使用echarts

    安装echarts依赖 npm install echarts -S 或者使用国内的淘宝镜像: 安装 npm in...

  • ionic 入门

    安装node.js默认安装(npm) 安装国内npm镜像 使用方式: 安装ionic ionic官网地址 :(ht...

  • JS学习笔记之开发环境搭建

    终端Nodejs这个安装很简单, 不累述 npm国内镜像镜像推荐使用淘宝的(cnmp)[https://npm.t...

  • React-Native极光推送双端配置

    开发步骤 安装WebStorm,激活使用 安装node到默认位置 配置npm的镜像资源(国内访问 npm安装yar...

  • pip

    pip更新 使用更新库 镜像 使用国外的镜像会比较慢,甚至安装失败,可以转成国内镜像: 安装:

  • 淘宝镜像node-sass无法安装的完美解决

    先上结论:使用淘宝的npm镜像来安装,也是没有安装上node-sass,报错截图: 创建失败。 使用命令:npm ...

  • MarkDown( NV )

    0.npm使用国内的淘宝镜像#### 1)先安装###### npm install -g cnpm --regi...

  • Electron使用

    1.安装node.js 2.安装electron 通过npm安装 3.使用淘宝 NPM 镜像 大家都知道国内直接...

网友评论

      本文标题:npm使用国内镜像解决安装连接失败错误

      本文链接:https://www.haomeiwen.com/subject/crslmxtx.html