我正在尝试安装 Material Top Tabs Navigator React Native 版本 6.xx 但出现错误

I'm trying to install Material Top Tabs Navigator React Native version 6.xx but getting errors

我是 React Native 的新手,在 运行 这个命令 npm install @react-navigation/material-top-tabs react-native-tab-view

之后我遇到了以下错误
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: AppName@0.0.1
npm ERR! Found: @react-navigation/native@5.9.8
npm ERR! node_modules/@react-navigation/native
npm ERR!   @react-navigation/native@"^5.9.8" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @react-navigation/native@"^6.0.0" from @react-navigation/material-top-tabs@6.0.2
npm ERR! node_modules/@react-navigation/material-top-tabs
npm ERR!   @react-navigation/material-top-tabs@"*" 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 C:\Users\Name\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Name\AppData\Local\npm-cache\_logs21-09-08T06_50_05_697Z-debug.log

试试这样强制安装:

npm install @react-navigation/material-top-tabs react-native-tab-view --force

您可以通过降低npm 6.x.x版本来解决问题。

brew install nvm // If there's no nvm
mkdir ~/.nvm
vi ~/.bash_profile // If you use zsh open ~/.zshrc
source ~/.bash_profile or ~/.zshrc
nvm install 6
nvm use 6.x.x
  • .zshrc 或 .bash_profile
export NVM_DIR="$HOME/.nvm" 
[ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh" # This loads nvm 
[ -s "/usr/local/opt/nvm/etc/bash_completion.d/nvm" ] && . "/usr/local/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion

使用这个:

  1. yarn add @react-navigation/material-top-tabs
  2. yarn add react-native-tab-view