React导航AppRegistry未注册

时间:2019-11-17 17:39:18

标签: reactjs react-native react-navigation

我已经使用react-native init <proj>设置了一个全新的项目,并且构建良好。我在文档之后将react-navigation添加到了项目中。但是,我无法通过此错误:

Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

即使使用其文档中的单个文件堆栈示例:

import React from 'react';
import { View, Text } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

class HomeScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Home Screen</Text>
      </View>
    );
  }
}

const AppNavigator = createStackNavigator({
  Home: {
    screen: HomeScreen,
  },
});

export default createAppContainer(AppNavigator);

它不起作用。我对这里可能出现的问题不知所措,因为我正在使用带有其工作示例的基本安装,并且未添加任何其他内容。从重启捆绑器到清除我能想到的所有缓存,我都做了尝试。

1 个答案:

答案 0 :(得分:1)

确保您正在注册组件:

const App = createAppContainer(navigator):

AppRegistry.registerComponent(appName, () => App)