安装@react-navigation/stack@5.14.3时无法解析依赖关系树

Cha*_*lha 8 javascript node.js npm reactjs react-native

我创建了一个新项目react-native init MyProject,在 VSCode 中打开它后,我做的第一件事就是安装导航。

npm install @react-navigation/native @react-navigation/stack

它抛出错误,然后我单独执行了这意味着首先我npm install @react-navigation/native成功安装了它,然后我执行了此操作npm install @react-navigation/stack,然后错误再次出现:

 npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency
 tree npm ERR!  npm ERR! While resolving: MyProject@0.0.1 npm ERR!
 Found: react@17.0.1 npm ERR! node_modules/react npm ERR!  
 react@"17.0.1" from the root project npm ERR!   peer react@"*" from
 @react-navigation/stack@5.14.3 npm ERR!  
 node_modules/@react-navigation/stack npm ERR!    
 @react-navigation/stack@"^5.14.2" from the root project npm ERR!  npm
 ERR! Could not resolve dependency: npm ERR! peer react@"^16.0" from
 @react-native-community/masked-view@0.1.10 npm ERR!
 node_modules/@react-native-community/masked-view npm ERR!  
 @react-native-community/masked-view@"^0.1.10" from the root project
 npm ERR!   peer @react-native-community/masked-view@">= 0.1.0" from  
 @react-navigation/stack@5.14.3 npm ERR!  
 node_modules/@react-navigation/stack npm ERR!    
 @react-navigation/stack@"^5.14.2" 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 /Users/chaudhrytalha/.npm/eresolve-report.txt for a full
 report.
 
 npm ERR! A complete log of this run can be found in: npm ERR!    
 /Users/chaudhrytalha/.npm/_logs/2021-03-17T10_09_02_128Z-debug.log
Run Code Online (Sandbox Code Playgroud)

我什至尝试安装npm install @react-native-community/masked-view但遇到类似的错误。

小智 8

这将解决问题

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


小智 -1

尝试将导航安装在与您的项目相同的目录中

  • 答案应该有一个可行的或尝试的解决方案。如果您有意见,请以评论的形式发表。 (2认同)