You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:无法解决@react-native-community/async-storage依赖冲突问题

解决React 17.0.2与@react-native-community/async-storage@1.12.1的依赖冲突

问题重现

执行npm命令时出现如下依赖冲突错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @react-native-community/async-storage@1.12.1
npm ERR! Found: react@17.0.2
npm ERR! node_modules/react
npm ERR!   react@"^17.0.2" from the root project
npm ERR!   peer react@">=16.3.0" from @callstack/react-theme-provider@3.0.7
npm ERR!   node_modules/@callstack/react-theme-provider
npm ERR!     @callstack/react-theme-provider@"^3.0.7" from react-native-paper@4.12.4
npm ERR!     node_modules/react-native-paper
npm ERR!       react-native-paper@"^4.12.4" from the root project
npm ERR!   25 more (@react-native-community/masked-view, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8" from @react-native-community/async-storage@1.12.1
npm ERR! node_modules/@react-native-community/async-storage
npm ERR!   @react-native-community/async-storage@"^1.12.1" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react@16.14.0
npm ERR! node_modules/react
npm ERR!   peer react@"^16.8" from @react-native-community/async-storage@1.12.1
npm ERR!   node_modules/@react-native-community/async-storage
npm ERR!     @react-native-community/async-storage@"^1.12.1" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

核心冲突:项目使用的react@17.0.2与@react-native-community/async-storage@1.12.1要求的peer依赖react@^16.8版本不匹配。


解决方法

1. 升级async-storage到兼容React 17的版本

@react-native-community/async-storage从1.13.0版本开始已支持React 17,直接升级到最新稳定版即可解决冲突:

npm install @react-native-community/async-storage@latest

若需指定具体版本,可执行:

npm install @react-native-community/async-storage@1.13.0

2. 使用--legacy-peer-deps跳过严格peer依赖检查

npm v7及以上默认启用严格的peer依赖校验,该参数可回到v6的宽松模式,暂时绕过冲突:

npm install --legacy-peer-deps

⚠️ 注意:此方法仅跳过校验,不解决本质冲突,若依赖实际存在兼容性问题可能引发运行时错误,适合临时验证或确认依赖可兼容的场景。

3. 降级React到兼容的16.x版本

若项目其他依赖暂不支持React 17,可将React降级到错误提示中指定的兼容版本16.14.0:

npm install react@16.14.0 react-dom@16.14.0

⚠️ 注意:降级前需确认项目中所有其他依赖是否都支持React 16.x版本,避免引发新的依赖冲突。


内容的提问来源于stack exchange,提问作者patelhash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 05:05:31