我无法使用React Navigation v4解决此捆绑错误

时间:2019-10-06 06:39:58

标签: react-native react-navigation react-navigation-stack

捆绑失败:错误:无法从react-navigation-stack解析模块App.js:在项目内找不到react-navigation-stack。

我尝试删除节点模块并重新安装它们,清除缓存,在新的新项目中尝试相同的操作,但没有结果

Package.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);

3 个答案:

答案 0 :(得分:2)

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

yarn add react-navigation-stack

npm install react-navigation-stack

答案 1 :(得分:0)

答案 2 :(得分:0)

npm install react-navigation-stack

npm install react-navigation-stack --save