概述
由于一些原因,可能需要进行镜像切换,一会淘宝镜像,一会官方镜像。这里来简单的记录下。
设置为淘宝镜像
- npm 设置为淘宝镜像
npm config set registry https://registry.npm.taobao.org/
- yarn 设置为淘宝镜像
yarn config set registry https://registry.npm.taobao.org/
设置为官方镜像
- npm 设置为官方镜像
npm config set registry https://registry.npmjs.org/
- yarn 设置为官方镜像
yarn config set registry https://registry.yarnpkg.com
判断是否设置成功
- yarn
yarn config get registry
执行上面这条命令后,查看控制台输出是否为你设置的镜像地址。
- npm
npm get registry
执行上面这条命令后,查看控制台输出是否为你设置的镜像地址。
问题回顾
- 描述
本地设置为淘宝镜像后,通过 yarn add react-native-modal 时,提示依赖包 react-native-animatable 无法找到。 - 分析
尝试多次后,依然无法解决。切换到 npm i react-native-modal 安装,能够找到了,结果项目里面报各种奇怪的错误。可能是我之前一直用的 yarn 来做依赖包管理有关。
到这里,分析可能跟镜像源有关。 - 解决
基于步骤 2 的分析,找到切换为官方镜像源的方式,将镜像源切换回官方,再执行 yarn add react-native-modal,执行成功。并且在执行 yarn android 的时候也不会报错。
欢迎关注我的公众号,一起进步!