反应导航-createStackNavigator错误-“未定义不是函数”

时间:2018-10-09 22:19:36

标签: javascript react-native react-navigation

我创建了以下代码以导入到app.js

import React from "react";
import { View } from "react-native";
import { createStackNavigator } from "react-navigation";
import HomeScreen from '../screens/HomeScreen';
import ProfileScreen from '../screens/auth/ProfileScreen';
import FilterScreen from '../screens/FilterScreen';

  const Routes = createStackNavigator(
      {
        Home: {
          screen: HomeScreen
        },
        Filters: {
          screen: FilterScreen
        },
        Profile: {
          screen: ProfileScreen
        }
      },
      {
        initialRouteName: "Home",
        navigationOptions: {
          headerTitleStyle: {
            fontWeight: "bold",
            color: "#fff",
          },
          headerTintColor: "#fff"
        }
      }
    );

    export default Routes;

我要按如下所示导入app.js

import Routes from './navigation/StackNavigator';

在此阶段预览我的应用程序时,出现以下错误:

undefined is not a function (near '...(0, 

_reactNavigation.createStackNavigator)...')

<unknown>
    C:\Apps\test\app\navigation\StackNavigator.js:9:6
loadModuleImplementation
    C:\Apps\test\app\node_modules\metro\src\lib\polyfills\require.js:213:12
<unknown>
    C:\Apps\test\app\App.js:7
loadModuleImplementation
    C:\Apps\test\app\node_modules\metro\src\lib\polyfills\require.js:213:12
<unknown>
    C:\Apps\test\app\node_modules\expo\AppEntry.js:2
loadModuleImplementation
    C:\Apps\test\app\node_modules\metro\src\lib\polyfills\require.js:213:12
guardedLoadModule
    C:\Apps\test\app\node_modules\metro\src\lib\polyfills\require.js:140:45
global code
    <unknown file>:0

有人知道什么可能是错的吗?我正在撕头发!任何建议将不胜感激!

1 个答案:

答案 0 :(得分:0)

建议:

  • 重命名路由到其他地方,例如Routes1(在app.jsnavigation/StackNavigator中)
  • 缩小错误范围,例如从createStackNavigator中删除选项,然后尝试执行以下操作:

    const Routes1 = createStackNavigator();

    export default Routes1;

  • 在此文件中尝试使用标签导航器(而不是stackNavigator),看看它是否可以正常工作。

  • 清理并强制重新安装模块