临时修改yarn源

yarn save package_name --registry https://registry.npm.taobao.org/

        永久修改yarn源

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

        yarn官方源

yarn config set registry https://registry.yarnpkg.com

        查看当前镜像源

yarn config get registry

------------------------------------------------------分割线-----------------------------------------------------------------       以下记录一下今天遇到的奇葩问题:想着拿来一个公司的项目运行一下看看效果,结果在使用yarn install时,一直报错

error An unexpected error occurred: "https://registry.yarnpkg.com/@ant-design/colors/-/colors-3.2.2.tgz: connect ETIMEDOUT 104.16.20.35:443".

        检查了一下发现yarn源已经更换,又想到是不是因为yarn还是不稳定,尝试使用tyarn进行依赖包安装,结果是一样的,完全没有改变。然后就注意到工程中的yarn.lock文件。在使用安装命令时,命令的全部内容是

yarn install --pure-lockfile

        会优先使用lockfile,所以去掉这个文件,让指令重新生成就可以了。最后简单介绍一下yarn.lock文件,官网上对于这个文件的解释是:

Managed by Yarn
Your yarn.lock file is auto-generated and should be handled entirely by Yarn. As you add/upgrade/remove dependencies with the Yarn CLI, it will automatically update your yarn.lock file. Do not edit this file directly as it is easy to break something.

Current package only
During install Yarn will only use the top-level yarn.lock file and will ignore any yarn.lock files that exist within dependencies. The top-level yarn.lock file includes everything Yarn needs to lock the versions of all packages in the entire dependency tree.

        解释起来就是

被Yarn所管理
您的yarn.lock文件是自动生成的,也应该完全由Yarn来处理。当你使用Yarn CLI添加/升级/删除依赖项的时,它将自动更新到您的yarn.lock文件。不要直接编辑这个文件,因为很容易造成破坏。

仅限当前包
在安装期间,Yarn将仅使用顶级yarn.lock文件,并将忽略依赖项中存在的任何yarn.lock文件。顶级yarn.lock文件包含Yarn需要锁定整个依赖关系树中所有包的版本的所有内容。

        yarn使用确定型算法,在将文件放置到需要的位置之前构建整个依赖关系树。安装过程中重要信息存储到yarn.lock文件中,以便可以在安装依赖关系的每个系统之间共享。此文件包含有关已安装的每个依赖项的确切版本的信息以及代码的校验和以确保代码完全相同。

  • 此文件会锁定你安装的每个依赖项的版本,这可以确保你不会意外获得不良依赖!
  • 并且会避免由于开发人员意外更改或则更新版本,而导致糟糕的情况!

最后将tyarn的安装命令记录一下

npm install yarn tyarn -g