react-navigation/stack找不到,尽管我已经安装了它

fwzugrvs  于 2023-10-22  发布在  React
关注(0)|答案(2)|浏览(154)

大家好,我正在学习一个关于react native的在线教程,但我遇到了一个问题:

\DUH\src\navigation\Navigator.tsx: @react-navigation/stack could not be found within the project or in these dire
ctories:
  node_modules
  ..\..\..\..\node_modules
   6 |   createStackNavigator,
   7 |   StackNavigationProp,
>  8 | } from '@react-navigation/stack';
     |         ^
   9 |
  10 | import * as routes from './routes';
  11 | import {SelectImageScreen} from '../screens/SelectImageScreen';

下面是我的package.json:

{
  "name": "DUH",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest"
  },
  "dependencies": {
    "@react-navigation/native": "^6.1.8",
    "react": "18.2.0",
    "react-native": "0.72.6",
    "react-native-gesture-handler": "^2.13.2",
    "react-navigation-stack": "^2.10.4"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/eslint-config": "^0.72.2",
    "@react-native/metro-config": "^0.72.11",
    "@tsconfig/react-native": "^3.0.0",
    "@types/react": "^18.0.24",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.2.1",
    "eslint": "^8.19.0",
    "jest": "^29.2.1",
    "metro-react-native-babel-preset": "0.76.8",
    "prettier": "^2.4.1",
    "react-test-renderer": "18.2.0",
    "typescript": "4.8.4"
  },
  "engines": {
    "node": ">=16"
  }
}

正如你在dependencies下看到的,我确实安装了react-navigation-stack:"react-navigation-stack": "^2.10.4"
我的问题是:如何修复此错误??
我使用以下命令安装了react-navigation-stack:npm install react-navigation-stack,我在这篇文章中发现:i could not resolve this bundling error with react navigation v4

ix0qys7i

ix0qys7i1#

您安装了错误的软件包:您需要安装@react-navigation/stack,而不是react-navigation-stack。这两个包是不一样的。

npm install @react-navigation/stack

yarn add @react-navigation/stack
lrl1mhuk

lrl1mhuk2#

如果你在Mac上开发iOS,你还需要安装pod(通过Cocoapods)来完成链接。

npx pod-install ios

更多信息:https://reactnavigation.org/docs/stack-navigator/

相关问题