我无法用react navigation v4解决此绑定错误

rks48beu  于 2023-02-05  发布在  React
关注(0)|答案(4)|浏览(137)

绑定失败:错误:无法从App.js解析模块react-navigation-stack:未能在项目中找到react-navigation-stack。
我尝试删除节点模块并重新安装它们,清除缓存,在新的项目中尝试相同的操作,但没有结果
软件包. json文件

{
  "name": "navigator",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.9.0",
    "react-native": "0.61.2",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-reanimated": "^1.3.0",
    "react-native-screens": "1.0.0-alpha.23",
    "react-navigation": "^4.0.10"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

App.js

import React from 'react';
    import { View, Text } from 'react-native';
    import { createAppContainer } from 'react-navigation';
    import { createStackNavigator } from 'react-navigation-stack';
    import HomeScreen from './src/screens/HomeScreen';
    import ComponentScreen from './src/screens/ComponentScreen';

    const navigator = createStackNavigator(
      {
        Home: HomeScreen
      },
      {
        initialRouteName: 'Home',
        defaultNavigationOptions: {
          title: 'App'
        }
      }
    );

    export default createAppContainer(navigator);
7gs2gvoe

7gs2gvoe1#

您的package.json没有要使用的模块。您需要安装模块。

yarn add react-navigation-stack

npm install react-navigation-stack
owfi6suc

owfi6suc3#

npm install react-navigation-stack

npm install react-navigation-stack --save
ie3xauqp

ie3xauqp4#

可能不是每个人的答案。我也有同样的问题,但我只需要重建项目并运行。

相关问题