React Native 并没有死!

尽管Airbnb和Udacity等企业弃用ReactNative,转向原生技术开发,但ReactNative社区依然活跃。Facebook正积极改进ReactNative,吸收Flutter和Vue.js的优点,使其与原生架构更好地融合。此外,第三方库如Expo也为ReactNative带来了新的活力。

最近的React Native 备受打击,Google 发布了首个 Flutter 预览版、Vue.js 在 GitHub 上的 star 数量超过了 React.js,而如今全球著名的民宿预订平台 Airbnb 突然宣布要弃 React Native 坑而逃,回归原生技术开发。最近在线教育机构Udacity 的移动团队也宣布其已经删除了应用中使用 React Native 编写的所有功能。

虽然厂商纷纷弃React Native而去,但我相信facebook不会轻言放弃,厂商的离去反而会让facebook更好的审视React Native优缺点,在这次的大规模重构中,解决厂商提出的一些问题,并且会吸收Flutter和Vue.js的优点,从而使React Native与原生架构结合得更好,让React Native更加完美!

目前 React Native 社区仍然很活跃,而且 Expo 等公司也做出了许多突破性的库,如 react-native-gesture-handler 等。所以说,虽然 Airbnb 、Udacity弃用了 React Native,但React Native 并没有死而且我相信会越来越好。

React Native开发圈也将回归,持续更新,给大家推荐好用的React Native组件和相关资讯,请大家继续关注并支持React Native和React Native开发圈!

欢迎关注React Native开发圈

code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving: react-native@0.57.8 npm ERR! Found: react@16.6.0 npm ERR! node_modules/react npm ERR! dev react@"16.6.0" from the root project npm ERR! peer react@"*" from @react-navigation/core@3.5.1 npm ERR! node_modules/@react-navigation/core npm ERR! peer @react-navigation/core@"^3.0.0" from @react-navigation/native@3.6.2 npm ERR! node_modules/@react-navigation/native npm ERR! @react-navigation/native@"^3.6.2" from react-navigation@4.0.7 npm ERR! node_modules/react-navigation npm ERR! dev react-navigation@"^4.0.7" from the root project npm ERR! @react-navigation/core@"^3.5.1" from react-navigation@4.0.7 npm ERR! node_modules/react-navigation npm ERR! dev react-navigation@"^4.0.7" from the root project npm ERR! 9 more (@react-navigation/native, enzyme-adapter-react-16, ...) npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer react@"16.6.3" from react-native@0.57.8 npm ERR! node_modules/react-native npm ERR! dev react-native@"~0.57.1" from the root project npm ERR! peer react-native@"*" from @react-navigation/native@3.6.2 npm ERR! node_modules/@react-navigation/native npm ERR! @react-navigation/native@"^3.6.2" from react-navigation@4.0.7 npm ERR! node_modules/react-navigation npm ERR! dev react-navigation@"^4.0.7" from the root project npm ERR! 4 more (react-native-safe-area-view, react-native-screens, ...) npm ERR! npm ERR! Conflicting peer dependency: react@16.6.3 npm ERR! node_modules/react npm ERR! peer react@"16.6.3" from react-native@0.57.8 npm ERR! node_modules/react-native npm ERR! dev react-native@"~0.57.1" from the root project npm ERR! peer react-native@"*" from @react-navigation/native@3.6.2 npm ERR! node_modules/@react-navigation/native npm ERR! @react-navigation/native@"^3.6.2" from react-navigation@4.0.7 npm ERR! node_modules/react-navigation npm ERR! node_modules/react-navigation npm ERR! node_modules/react-navigation npm ERR! dev react-navigation@"^4.0.7" from the root project npm ERR! node_modules/react-navigation npm ERR! node_modules/react-navigation npm ERR! node_modules/react-navigation npm ERR! dev react-navigation@"^4.0.7" from the root project npm ERR! 4 more (react-native-safe-area-view, react-native-screens, ...)
09-20
<think> 我们面对的问题是:在安装依赖时,npm 报错 ERESOLVE,原因是 react-native@0.57.8 要求 peer 依赖 react@16.6.3,而当前项目中的 react 版本是 16.6.0,导致依赖树解析失败。 根据引用[1]和引用[5]的内容,我们可以使用 `--legacy-peer-deps` 参数来忽略 peerDependencies 的冲突,继续安装。但这不是最根本的解决方法,因为它可能会留下潜在的兼容性问题。 更推荐的做法是升级项目中的 react 版本到 16.6.3(因为 16.6.0 和 16.6.3 都是小版本,升级通常不会引入破坏性变更,且 react-native@0.57.8 要求至少 16.6.0,而 16.6.3 是满足要求的)。 因此,我们可以采取以下步骤: 方案1:升级 react 到 16.6.3(推荐) 1. 在项目根目录下,执行: ``` npm install react@16.6.3 react-dom@16.6.3 ``` 注意:如果项目是 React Native 项目,则不需要安装 react-dom,但需要确保 react-native 的版本与 react 兼容。 2. 然后重新安装其他依赖,或者继续安装你原本要安装的包。 方案2:使用 --legacy-peer-deps 忽略冲突(临时解决) 如果你暂时不想升级 react,可以尝试在安装命令中添加 `--legacy-peer-deps` 参数,例如: ``` npm install --legacy-peer-deps ``` 或者安装特定包时: ``` npm install <package-name> --legacy-peer-deps ``` 但是,请注意,使用 `--legacy-peer-deps` 可能会导致运行时出现难以预料的问题,因为 peerDependencies 的版本要求通常是为了保证包的兼容性。 此外,根据引用[2]和引用[5]的说明,npm 从 v7 开始默认安装 peerDependencies,因此如果 peerDependencies 不满足就会报错。如果你不想升级 npm 包,也可以考虑降级 npm 到 v6(v6 不会因为 peerDependencies 冲突而中断安装)。 方案3:降级 npm 到 v6 执行: ``` npm install -g npm@6 ``` 然后重新运行安装命令。 但是,降级 npm 可能会影响其他项目的依赖解析,因此不是长久之计。 最佳实践是升级 react 到 16.6.3,因为它与 16.6.0 非常接近,且 react-native@0.57.8 明确要求 react@16.6.3(至少是 16.6.0,但 16.6.3 修复了一些问题)。 步骤总结(方案1): 1. 打开终端,进入项目目录。 2. 运行:`npm install react@16.6.3` 3. 如果有 react-dom,则运行:`npm install react-dom@16.6.3` 4. 然后重新运行你之前的安装命令(比如 `npm install` 或者安装某个包)。 如果问题仍然存在,可以尝试删除 node_modules 和 package-lock.json 后重新安装: ``` rm -rf node_modules rm package-lock.json npm install ``` 注意:在 Windows 系统上,删除命令使用: ``` rmdir /s /q node_modules del package-lock.json ``` 最后,如果升级 react 后,其他包对 react 的版本有要求(比如要求16.5.0),那么可能还需要调整其他依赖。但根据错误信息,目前只有 react-native@0.57.8 要求 react@16.6.3,而你已经升级,所以应该可以解决。 现在,让我们根据上述分析给出具体回答。 </think> ### 解决 npm ERESOLVE 错误:React Native 0.57.8 与 React 16.6.0 版本冲突 #### 问题核心原因 React Native 0.57.8 在 `peerDependencies` 中明确要求使用 React 16.6.3,而您的项目当前安装的是 React 16.6.0。npm v7+ 会严格检查这种 peer 依赖关系,导致依赖树解析失败[^1][^5]。错误本质是: $$ \text{react-native@0.57.8} \Rightarrow \text{requires react@16.6.3} \quad \text{but} \quad \text{project has react@16.6.0} $$ --- ### 三种解决方案(按推荐顺序) #### ✅ 方案1:升级 React 到兼容版本(最佳实践) ```bash # 升级 React 到精确匹配版本 npm install react@16.6.3 react-native@0.57.8 # 验证版本 npm list react --depth=0 # 应显示 react@16.6.3 ``` **原理**: React Native 0.57.8 的 `peerDependencies` 声明要求 React 16.6.3[^1]: ```json "peerDependencies": { "react": "16.6.3" } ``` **优势**: - 永久解决兼容性问题 - 避免潜在运行时错误 - 符合 React Native 官方的版本配对要求 #### ⚠️ 方案2:临时忽略版本冲突(快速修复) ```bash # 使用 --legacy-peer-deps 跳过 peer 依赖检查 npm install --legacy-peer-deps ``` **原理**: 模拟 npm v6 的行为,允许安装不匹配的 peer 依赖[^1][^5]: $$ \text{npm install} + \text{--legacy-peer-deps} \Rightarrow \text{跳过 peerDependency 检查} $$ **风险**: - 可能导致 React Native 运行时异常(如 API 不兼容) - 仅建议临时测试使用 #### 🔧 方案3:强制覆盖依赖版本(高风险) ```bash # 强制使用当前 React 版本 npm install --force ``` **原理**: 用本地版本覆盖远程仓库的要求 **严重警告**: - 可能导致 React Native 功能异常 - 触发 `componentWillMount` 等废弃 API 的崩溃(React 16.6.0 已弃用部分 API) --- ### 验证解决效果 ```bash # 检查依赖树是否正常 npm ls --all # 确认无 ERESOLVE 错误 npm install ``` ### 附加调试步骤(若问题持续) 1. **清理缓存与锁定文件**: ```bash npm cache clean --force rm -rf node_modules package-lock.json ``` 2. **检查依赖冲突源**: ```bash npm view react-native@0.57.8 peerDependencies ``` --- ### 关键知识补充 1. **peerDependency 机制**: React Native 声明 peerDependency 是为了确保宿主项目提供正确版本的 React,避免打包多个 React 副本[^5]。 2. **版本兼容性**: React 16.6.x 包含重要安全修复,16.6.0 → 16.6.3 的升级包含关键补丁([更新日志](https://github.com/facebook/react/releases/tag/v16.6.3))。 > ⚠️ **重要提醒**:React NativeReact 版本极其敏感,错误配对可能导致白屏崩溃。建议优先使用方案1[^1][^2]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值