如何安装反应导航?

How to install react navigation?

我是编码初学者,这意味着我遵循 youtube 上的教程。我正在制作的项目使用 react-navigation/native,但是当我尝试安装它时,它给了我这个错误:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: react-native-elements@3.4.2
npm ERR! Found: react-native-safe-area-context@4.2.5
npm ERR! node_modules/react-native-safe-area-context
npm ERR!   react-native-safe-area-context@"^4.2.5" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react-native-safe-area-context@"^3.1.9" from react-native-elements@3.4.2
npm ERR! node_modules/react-native-elements     
npm ERR!   react-native-elements@"^3.4.2" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: react-native-safe-area-context@3.4.1
npm ERR! node_modules/react-native-safe-area-context
npm ERR!   peer react-native-safe-area-context@"^3.1.9" from react-native-elements@3.4.2        
npm ERR!   node_modules/react-native-elements   
npm ERR!     react-native-elements@"^3.4.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 C:\Users\ps3pl\AppData\Local\npm-cache\eresolve-report.txt for a full r
eport.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ps3pl\AppData\Local\npm-cache\_logs22-05-29T06_56_49_981Z-d
ebug-0.log

我正在使用 EXPO 进行构建 这是我的 package.json 文件:

{
  "name": "uber-clone",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@reduxjs/toolkit": "^1.8.2",
    "expo": "~45.0.0",
    "expo-status-bar": "~1.3.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-native-elements": "^3.4.2",
    "react-native-safe-area-context": "^4.2.5",
    "react-native-vector-icons": "^9.1.0",
    "react-native-web": "0.17.7",
    "react-redux": "^8.0.2",
    "tailwind-react-native-classnames": "^1.5.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}

尝试使用标志 --legacy-peer-deps

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

你的问题和

差不多

仔细阅读答案。

解决方法:

按照错误消息的建议尝试使用正确的软件包版本解决问题。

如果您做不到,请使用

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

npm install @react-navigation/native --force

确保您在开发时可能会遇到冲突问题。