一开始使用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立马成功安装
网友评论