yarn的安装
npm install -g yarn
安装完成之后查看版本
yarn -v 或 yarn --version
常用命令
yarn info #显示某个包信息
yarn list # 列出当前项目的依赖
yarn list --depth=0 # 限制依赖的深度
yarn config set key value # 设置
yarn config get key # 读取值
yarn config delete key # 删除
yarn config list # 显示当前配置
yarn config set registry https://registry.npm.taobao.org # 设置淘宝镜像
yarn cache #缓存
yarn cache list # 列出已缓存的每个包
yarn cache dir # 返回 全局缓存位置
yarn cache clean # 清除缓存
与npm命令对比
yarn | npm | 命令说明 |
---|---|---|
yarn init | npm init | 项目初始化 |
yarn install | npm instal | 安装默认依赖 |
yarn add react | npm install react --save | 安装某个依赖,并保存到package.json中 |
yarn remove react | npm uninstall react --save | 移除某个依赖 |
yarn add react --dev | npm install react --save–dev | 安装某个开发时依赖 |
yarn upgrade react | npm update react --save | 更新某个依赖 |
yarn global add react | npm install react --global | 安装某个全局依赖 |
yarn run/test | npm run/test | 运行某个命令 |
使用时遇到的报错信息及解决方法(持续更新)
1、yarn安装模块时,出现错误
yarn add gulp-concat #输入
#输出
yarn add v1.22.10
info No lockfile found.
[1/4] Resolving packages...
error An unexpected error occurred: "http://registry.cnpmjs.org/gulp-concat: Hostname/IP does not match certificate's altnames: Host: registry.cnpmjs.org. is not in the cert's altnames: DNS:r.cnpmjs.org".
info If you think this is a bug, please open a bug report with the information provided in "C:\\Users\\XZC\\Desktop\\test\\yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
遇到这个问题是由于网络原因导致下载依赖包请求超时报错,更换网络下载即可,命令行输入:
npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist
yarn config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
最后重新安装成功!