npm仓库设置
1. 默认仓库,是国外的,安装会很慢
D:\workspace\vue-test>npm config get registry https://registry.npmjs.org/
2. 设置npm仓库
D:\workspace\vue-test>npm config set registry https://registry.apm.taobao.org D:\workspace\vue-test>npm config get registry https://registry.apm.taobao.org/
3. 安装 install
npm 安装命令(--save/--save-dev)
–save-dev 简写: -D 适用于各类loder , plugin, babel, webpack等
-save 简写 :-S 适用于 UI框架,vue等
3.1、 npm install moduleName
- 该模块依赖会写入dependencies节点
- 安装在该项目的node_modules目录下
- npm install 初始化不会下载模块,需要自己手动下载
3.2、npm install moduleName --save-dev
- 该模块依赖会写入devDependencies节点
- 安装在该项目的node_modules目录下
- npm install 初始化时会自动下载模块
3.3、npm install moduleName --save
- 该模块依赖会写入dependencies节点
- 安装在该项目的node_modules目录下
- npm install 初始化时会自动下载模块
3.4、npm install moduleName -g
- 该模块依赖不会被写入devDependencies或dependencies节点
- 安装至全局中
- npm install 初始化时不会自动下载模块
仅仅在开发中需要用到的,使用–save-dev
删除包命令 npm uninstall moduleName //加-g表示全局
4. 安装踩坑
执行 npm install vue vue-cli -g, 报错如下:
npm ERR! code ERR_TLS_CERT_ALTNAME_INVALID npm ERR! errno ERR_TLS_CERT_ALTNAME_INVALID npm ERR! request to https://registry.apm.taobao.org/vue failed, reason: Hostname/IP does not match certificate's altnames: Host: registry.apm.taobao.org . is not in the cert's altnames: DNS:*.tbcdn.cn, DNS:*.taobao.com, DNS:*.alicdn.com, DNS:*.cmos.greencompute.org, DNS:cmos.greencompute.org, DNS:m.intl. taobao.com, DNS:*.mobgslb.tbcache.com, DNS:*.alikunlun.com, DNS:alikunlun.com, DNS:*.django.t.taobao.com, DNS:alicdn.com, DNS:*.tbcache.com, DNS:*.tmall .com, DNS:*.1688.com, DNS:*.3c.tmall.com, DNS:*.alibaba.com, DNS:*.aliexpress.com, DNS:*.aliqin.tmall.com, DNS:*.alitrip.com, DNS:*.aliyun.com, DNS:*.ca iniao.com, DNS:*.cainiao.com.cn, DNS:*.chi.taobao.com, DNS:*.chi.tmall.com, DNS:*.china.taobao.com, DNS:*.dingtalk.com, DNS:*.etao.com, DNS:*.feizhu.cn, DNS:*.feizhu.com, DNS:*.fliggy.com, DNS:*.fliggy.hk, DNS:*.food.tmall.com, DNS:*.jia.taobao.com, DNS:*.jia.tmall.com, DNS:*.ju.taobao.com, DNS:*.juhuas uan.com, DNS:*.lw.aliimg.com, DNS:*.m.1688.com, DNS:*.m.alibaba.com, DNS:*.m.alitrip.com, DNS:*.m.cainiao.com, DNS:*.m.etao.com, DNS:*.m.taobao.com, DNS :*.m.taopiaopiao.com, DNS:*.m.tmall.com, DNS:*.m.tmall.hk, DNS:*.mei.com, DNS:*.taopiaopiao.com, DNS:*.tmall.hk, DNS:*.trip.taobao.com, DNS:*.xiami.com, DNS:1688.com, DNS:alibaba.com, DNS:aliexpress.com, DNS:alitrip.com, DNS:aliyun.com, DNS:cainiao.com, DNS:cainiao.com.cn, DNS:dingtalk.com, DNS:etao.com , DNS:feizhu.cn, DNS:feizhu.com, DNS:fliggy.com, DNS:fliggy.hk, DNS:juhuasuan.com, DNS:mei.com, DNS:taobao.com, DNS:taopiaopiao.com, DNS:tmall.hk, DNS:x iami.com, DNS:tmall.com, DNS:tbcdn.cnf
方案:
方案1:npm config set strict-ssl false, 关闭tls。 报了另外一个错误。如下:
PS D:\workspace\vue_js_lesson_demo> npm install vue vue-cli -g npm ERR! code E403 npm ERR! 403 403 Forbidden - GET https://registry.apm.taobao.org/vue npm ERR! 403 In most cases, you or one of your dependencies are requesting npm ERR! 403 a package version that is forbidden by your security policy, or npm ERR! 403 on a server you do not have access to.