导入路由后反应本机,typerError

时间:2020-10-27 07:36:33

标签: javascript reactjs react-native

我在我的物理设备上运行我的React Native应用程序,当我在我的app.js中导入routesContainer时遇到了该错误。有人知道为什么我会收到此错误吗?

TypeError: Super expression must either be null or a function
[Mon Oct 26 2020 10:37:19.635]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
[Mon Oct 26 2020 10:37:19.636]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
[Mon Oct 26 2020 10:37:19.637]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

那是导入路由容器后出现的错误,下面是我的routes.js

routes.js

const AuthStack = createStackNavigator(
  {
    // animationA:AnimationA,
    login: Login,
    welcome: Welcome,
    forgetPassword: ForgetPassword,
    registrationCodeStep: RegistrationCodeStep,
    registrationCode: RegistrationCode,
    coachSignup: CoachSignup,
    playerSignup: PlayerSignup,
  },
  {
    headerMode: 'none',
  },
);

const CoachStack = createDrawerNavigator(
  {
    dashboard: createStackNavigator(
      {
        coachDashboard: CoachDashboard,
        notifications: Notifications,
      },
      {
        headerMode: 'none',
      },
    ),
    coachTeam: createStackNavigator(
      {
        coachMyTeam: CoachMyTeam,
        createTeam: CreateTeam,
        coachTeamPlayerList: CoachTeamPlayerList,
        playerDetails: PlayerDetails,
        invitePlayer: InvitePlayer,
      },

      {
        headerMode: 'none',
      },
    ),
    coachTraining: createStackNavigator(
      {
        training: Training,
        addEditTraining: AddEditTraining,
        coachTeamPlayerList: CoachTeamPlayerList,
        openTraining: OpenTraining,
        locationPicker: LocationPicker,
        playerDetails: PlayerDetails,
        weburl: WebUrl,
      },

      {
        headerMode: 'none',
      },
    ),
    coachGames: createStackNavigator(
      {
        games: Games,
        weburl: WebUrl,
      },
      {
        headerMode: 'none',
      },
    ),
    coachChat: createStackNavigator(
      {
        myChat: MyChat,
        chat: Chat,
        addUserChat: AddUserChat,
      },
      {
        headerMode: 'none',
      },
    ),

    gallery: Gallery,
    scoreboard: Scoreboard,
    accounts: Accounts,
    changePassword: ChangePassword,
    editProfile: EditProfile,
  },

  {
    drawerPosition: 'right',
    contentComponent: CustomDrawerContentComponent,
  },
);

const PlayerStack = createDrawerNavigator(
  {
    dashboard: createStackNavigator(
      {
        playerDashboard: PlayerDashboard,
        playerMyTeam: PlayerMyTeam,
        playerDetails: PlayerDetails,
        playerTeamList: PlayerTeamList,
        registrationCode: RegistrationCode,
        notifications: Notifications,
      },
      {
        headerMode: 'none',
      },
    ),
    playerGamesStack: createStackNavigator(
      {
        playerGames: PlayerGames,
        weburl: WebUrl,
      },
      {
        headerMode: 'none',
      },
    ),
    playerTrainingStack: createStackNavigator(
      {
        playerTraining: PlayerTraining,
        openTraining: OpenTraining,
        locationPicker: LocationPicker,
        playerDetails: PlayerDetails,
        weburl: WebUrl,
      },
      {
        headerMode: 'none',
      },
    ),
    playerGallery: PlayerGallery,
    changePassword: ChangePassword,
    // accounts:Accounts,
    pAccounts: Accounts,
    playerScoreBoard: PlayerScoreboard,
    playerEdit: PlayerEdit,
    playerChat: createStackNavigator(
      {
        myChat: MyChat,
        chat: Chat,
        addUserChat: AddUserChat,
      },
      {
        headerMode: 'none',
      },
    ),
  },
  {
    drawerPosition: 'right',
    contentComponent: CustomDrawerContentComponent,
  },
);

const RoutesContainer = data => {
  let intial_Route = 'AuthStack';
  if (data.isLogin) {
    intial_Route =
      data.userType == USER_TYPE.PLAYER ? 'PlayerStack' : 'CoachStack';
  }

  return createAppContainer(
    createSwitchNavigator(
      {
        AuthStack,
        CoachStack,
        PlayerStack,
      },
      {initialRouteName: intial_Route},
    ),
  );
};

export default RoutesContainer;

两天后我需要调试该代码,我发现route.js中有错误,但不知道这里出了什么问题?谁能告诉我

1 个答案:

答案 0 :(得分:0)

关注班级名称

首先,如果您确定要从正确命名的类扩展,例如 React.Component ,而不是 React.component React.createComponent ,如果是这种情况,则可能需要升级React版本。以下是有关要从其扩展的类的更多信息。

升级React

React从0.13.0版本开始仅支持 ES6语法类(请参见React官方文档here

但是在此之前,当您使用时:

例如) class HelloMessage extends React.Component

您试图使用ES6关键字(扩展)从未使用ES6类定义的类中继承子类。这可能就是为什么您在使用超定义等时遇到这种意外行为的原因。

因此,更新到React新版本。

循环依赖

如果您具有循环导入结构,也会发生这种情况。一个模块导入另一个模块,反之亦然。在这种情况下,您只需要重构代码即可避免它。See here