无法在 React Native 中使用 `npm install @react-navigation/stack` 安装“@react-navigation/stack”

Unable to install "@react-navigation/stack" using `npm install @react-navigation/stack` in reactNative

React Native 应用程序中制作导航需要安装 @react-navigation/stack 使用 npm install @react-navigation/stack 和我已经尝试过了,但每次都失败了。

NPM 版本: 7.19.1 节点版本: v15.14.0 Expo 版本: 4.8.1

在 运行 npm install @react-navigation/stack 这个命令之后我遇到了下面的错误,

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: @react-navigation/native@3.8.4
npm ERR! node_modules/@react-navigation/native
npm ERR!   @react-navigation/native@"^3.8.4" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @react-navigation/native@"^6.0.0" from @react-navigation/stack@6.0.1
npm ERR! node_modules/@react-navigation/stack
npm ERR!   @react-navigation/stack@"*" 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.
npm ERR! 
npm ERR! See /home/imdadul/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/imdadul/.npm/_logs/2021-08-04T07_46_39_555Z-debug.log

注:请关注附件,有这方面知识的可以帮帮我。 非常感谢!

您有依赖冲突,这意味着依赖不正确并且可能损坏。您可以尝试使用 --force--legacy-peer-deps 运行 命令,看看是否有帮助。

npm install @react-navigation/stack --force

npm install @react-navigation/stack --legacy-peer-deps

有时删除 node_modulespackage-lock.json 文件和 运行 命令 npm install @react-navigation/stack 或尝试 npm cache clean --force 可以工作。