美文网首页
yarn工具使用的坑

yarn工具使用的坑

作者: 年轻人多学点 | 来源:发表于2020-03-19 11:51 被阅读0次
lerna ERR! yarn install --mutex network:42424 --non-interactive exited 1
查明原因是:yarn的版本问题造成的,切换到稳定版本

 # yarn 升级最新版本

npm install yarn@latest -g
# 查看yarn历史版本

npm view yarn versions --json
# yarn 升级指定版本 (例:升级到1.21.3版本)

yarn upgrade v1.21.3
(稳定版本可参考yarn中文网)
https://yarn.bootcss.com/docs/install/#windows-stable](https://yarn.bootcss.com/docs/install/#windows-stable)

一. npm和yarn源的简单修改(以淘宝镜像为例)

npm

1. 临时修改(只生效一次)
npm install 包的名字 --registry https://registry.npm.taobao.org

2. 设置npm的配置项(全局配置)

查看npm源的当前地址

npm config get registry

设置淘宝镜像

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

yarn

1. 临时修改(只生效一次)
yarn save 包的名字 --registry https://registry.npm.taobao.org/

2. 设置yarn的配置项(全局配置)

查看yarn源的当前地址

yarn config get registry

设置淘宝镜像

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

二. 使用第三方软件快速修改、切换 npm和yarn的源(以淘宝镜像为例)

(1)分别修改npm和yarn源(经实际测试,这种方法修改一个源另一个源也会同时修改)

npm

nrm 是一个 NPM 源管理器,允许你快速地在如下 NPM 源间切换

安装
npm install -g nrm

列出可选的源
nrm ls

* npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
  taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/

带 * 的是当前使用的源

切换

切换到taobao镜像源

nrm use taobao

   Registry has been set to: https://registry.npm.taobao.org/

测试源的响应时间

测试所有源的响应时间:

nrm test

  npm ---- 2930ms
  cnpm --- 300ms
* taobao - 292ms
  nj ----- Fetch Error
  rednpm - Fetch Error
  npmMirror  1626ms
  edunpm - Fetch Error

可以多次测量来得到更精确的结果
更多nrm使用方法访问nrm的gitHub仓库
https://github.com/Pana/nrm

yarn

yrm 是一个 yarn源管理器,允许你快速地在yarn源间切换

安装
npm install -g yrm

列出可选的源
yrm ls

  npm ---- https://registry.npmjs.org/
  cnpm --- http://r.cnpmjs.org/
* taobao - https://registry.npm.taobao.org/
  nj ----- https://registry.nodejitsu.com/
  rednpm - http://registry.mirror.cqupt.edu.cn/
  npmMirror  https://skimdb.npmjs.com/registry/
  edunpm - http://registry.enpmjs.org/
  yarn --- https://registry.yarnpkg.com

带 * 的是当前使用的源

切换

切换到taobao镜像源

yrm use taobao

   YARN Registry has been set to: https://registry.npm.taobao.org/

测试源的响应时间

测试所有源的响应时间:

yrm test

  npm ---- 784ms
  cnpm --- 290ms
* taobao - 297ms
  nj ----- Fetch Error
  rednpm - Fetch Error
  npmMirror  1353ms
  edunpm - Fetch Error
  yarn --- Fetch Error

可以多次测量来得到更精确的结果
更多yrm使用方法访问yrm的gitHub仓库
https://github.com/i5ting/yrm

(2)使用双源管理工具cgr (特感谢缤纷扫落叶推荐)

安装
npm install -g cgr
Yarn 常用命令
npm install === yarn —— install安装是默认行为

npm install taco --save === yarn add taco —— taco包立即被保存到 package.json 中。

npm uninstall taco --save === yarn remove taco

npm install taco --save-dev === yarn add taco --dev

npm update --save === yarn upgrade

npm install taco@latest --save === yarn add taco

npm install taco --global === yarn global add taco —— 一如既往,请谨慎使用 global 标记。

注意:使用yarn或yarn install安装全部依赖时是根据package.json里的"dependencies"字段来决定的

npm init === yarn init

npm init --yes/-y === yarn init --yes/-y

npm link === yarn link

npm outdated === yarn outdated

npm publish === yarn publish

npm run === yarn run

npm cache clean === yarn cache clean

npm login === yarn login

npm test === yarn test

Yarn 独有的命令

yarn licenses ls —— 允许你检查依赖的许可信息
yarn licenses generate —— 自动创建依赖免责声明 license
yarn why taco —— 检查为什么会安装 taco,详细列出依赖它的其他包
yarn why vuepress —— 检查为什么会安装 vuepress,详细列出依赖它的其他包

特性

Yarn 除了让安装过程变得更快与更可靠,还添加了一些额外的特性,从而进一步简化依赖管理的工作流。

相关文章

  • yarn工具使用的坑

    一. npm和yarn源的简单修改(以淘宝镜像为例) npm 1. 临时修改(只生效一次) 2. 设置npm的配置...

  • React Native 使用Yarn (环境)

    React Native使用Yarn,Yarn是Facebook提供的替代npm的工具,可以加速node模块的下载...

  • Angular6 配置 hmr (热加载)

    前置条件 先安装项目依赖包 yarn ( 推荐使用 yarn 包管理工具 ) 安装 hmr 依赖包 yarn ad...

  • Vue开发遇到坑集锦 (持续更新)

    Npm或Yarn“坑”集 1.拉取项目后,使用yarn进行安装操作,提示如下 【解决方式:】 【原因说明:】先排查...

  • Yarn 介绍

    使用Yarn 定位:包管理工具,替代npm 安装速度快,版本锁定,缓存机制 安装 npm install yarn...

  • yarn构建vue项目

    yarn也是和npm的功能一样,都是一个包管理工具. 1、yarn的安装 说明:yarn的使用也是和npm一样,之...

  • 2019-09-27umi+dva+ant-design项目搭建

    新建文件夹在webstorm中打开itcast-react 一、安装和使用yarn包管理工具 参考:yarn常用用...

  • MRN踩坑总结

    MRN踩坑总结 删除了模块下的node_modules导致无法commit,使用yarn install 无效 解...

  • 单页应用开发的四类工程化工具

    单页应用开发需要使用四类工程化工具: 依赖管理(包管理):npm, yarn 打包工具:webpack 编译工具:...

  • yarn 和 npm 的区别

    包管理工具的安装:yarn的安装:下载软件,傻瓜式安装。注(PS):用npm进行安装yarn会报错,不能使用 np...

网友评论

      本文标题:yarn工具使用的坑

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