npm install执行时卡在@react-navigation/stack@"^6.3.17"步骤求助
执行npm install时进程卡在@react-navigation/stack环节,且伴随peer依赖版本冲突警告,即便更新了Node.js和npm也无法解决。以下是具体排查和解决步骤:
问题核心
从命令输出的警告能看出,项目依赖存在版本不兼容:
- 项目指定安装
@react-navigation/native@7.24.0,但实际解析到的是6.1.8版本 @react-navigation/bottom-tabs@6.5.9和@react-navigation/stack@6.3.18都要求peer依赖@react-navigation/native@^6.0.0,和项目指定的7.x版本冲突,这大概率是导致安装停滞的原因
命令输出如下:
npm WARN using --force Recommended protections disabled. npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: first@1.0.0 npm WARN Found: @react-navigation/native@6.1.8 npm WARN node_modules/@react-navigation/native npm WARN @react-navigation/native@"7.24.0" from the root project npm WARN 3 more (@react-navigation/bottom-tabs, ...) npm WARN npm WARN Could not resolve dependency: npm WARN peer @react-navigation/native@"^6.0.0" from @react-navigation/bottom-tabs@6.5.9 npm WARN node_modules/@react-navigation/bottom-tabs npm WARN @react-navigation/bottom-tabs@"^6.5.8" from the root project npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: first@1.0.0 npm WARN Found: @react-navigation/native@6.1.8 npm WARN node_modules/@react-navigation/native npm WARN @react-navigation/native@"7.24.0" from the root project npm WARN 3 more (@react-navigation/bottom-tabs, ...) npm WARN npm WARN Could not resolve dependency: npm WARN peer @react-navigation/native@"^6.0.0" from @react-navigation/stack@6.3.18 npm WARN node_modules/@react-navigation/stack npm WARN @react-navigation/stack@"^6.3.17" from the root project
解决步骤
1. 清理npm缓存并重新安装
缓存损坏可能导致安装异常,先清理缓存再重试:
npm cache clean --force
然后删除项目根目录下的node_modules文件夹和package-lock.json文件,重新执行:
npm install
2. 修复peer依赖版本冲突
版本不兼容是根本问题,二选一处理:
- 降级@react-navigation/native到6.x版本:修改
package.json中@react-navigation/native的版本为^6.1.8(或其他兼容6.x的版本),保存后重新执行npm install - 升级导航组件到适配7.x的版本:将
@react-navigation/bottom-tabs和@react-navigation/stack的版本更新为支持@react-navigation/native@7.x的版本
3. 跳过peer依赖检查(临时方案)
如果暂时不想调整版本,可以使用--legacy-peer-deps参数跳过严格的peer依赖检查:
npm install --legacy-peer-deps
4. 切换npm源(排查网络问题)
网络不稳定也可能导致安装停滞,切换到国内镜像源试试:
npm config set registry https://registry.npmmirror.com/
设置完成后重新执行npm install
内容的提问来源于stack exchange,提问作者Mahmud Isah
相关产品推荐
相关产品推荐

