gpt4 book ai didi

javascript - react 导航 - createStackNavigator 错误 - "Undefined is not a function"

转载 作者:搜寻专家 更新时间:2023-11-01 04:39:29 24 4
gpt4 key购买 nike

我创建了以下代码以导入到 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

有谁知道哪里出了问题?我要扯掉我的头发了!任何建议将不胜感激!

最佳答案

建议:

  • 将路线重命名为其他名称,例如Routes1(在 app.jsnavigation/StackNavigator 中)
  • 缩小错误的范围,例如从 createStackNavigator 中删除选项并尝试类似的操作:

    const Routes1 = createStackNavigator();

    export default Routes1;

  • 试试这个文件中的选项卡导航器(而不是 stackNavigator),看看它是否工作正常。

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

关于javascript - react 导航 - createStackNavigator 错误 - "Undefined is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52730105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com