Redux connect - 模块AppRegistry不是注册的可调用模块

休言女子非英物,夜夜龙泉壁上鸣。这篇文章主要讲述Redux connect - 模块AppRegistry不是注册的可调用模块相关的知识,希望能为你提供帮助。
我在启动一个新项目并实现redux和react-navigation后收到此错误Module AppRegistry is not a registered callable module
调试器逐步完成我的代码的初始化,但我无法看到抛出更具描述性的错误的位置。我唯一看到的是调试时确实没有调用runApplication的方法。由于react-redux,我的设置与默认的AppRegistry不同。

import React from 'react' import { Provider } from 'react-redux'; import configureStore from './store'; import AppReducer from './reducers'; import { persistStore } from 'redux-persist' import AppWithNavigationState from './navigator'export default class App extends React.Component { store = configureStore(AppReducer); constructor(props) { super(props); persistStore(this.store).purge(); }render() { return < Provider store={this.store}> < AppWithNavigationState /> < /Provider> } }

据我所知,没有必要注册我的App类,也不需要使用AppRegistry手动注册我的组件。我觉得我的代码应该受到责备,因为之前曾经有过工作,但堆栈跟踪并没有指向任何东西。
当然,当添加AppRegistery.registerComponent时,它的工作原理!但这并不能解释为什么以前没有必要这样做。
我的AppNavigator课程:
import React from 'react' import { BackHandler, } from 'react-native' import { addNavigationHelpers, StackNavigator, } from 'react-navigation' import { connect } from 'react-redux'import Start from './components/start' import Login from './components/login' import AppCamera from './components/camera'export const AppNavigator = StackNavigator({ Start: { screen: Start, navigationOptions: { title: 'App', }, }, Login: { screen: Login, navigationOptions: { title: 'Login', } }, Camera: { screen: AppCamera, navigationOptions: { title: 'Camera', } }}, { mode: 'modal', headerMode: 'none', }); // const AppWithNavigationState = ({ dispatch, nav }) => ( //< AppNavigator navigation={addNavigationHelpers({ dispatch, state: nav })} /> // ); export class AppWithNavigationState extends React.Component { constructor(props) { super(props); }componentWillMount() { BackHandler.addEventListener('hardwareBackPress', function() { const { dispatch, navigation, nav } = this.props; if (nav.routes.length === 1 & & (nav.routes[0].routeName === 'Login' || nav.routes[0].routeName === 'Start')) { return false; } // if (shouldCloseApp(nav)) return false dispatch({ type: 'Navigation/BACK' }); return true; }.bind(this)); }componentWillUnmount() { BackHandler.removeEventListener('hardwareBackPress'); }render() { return < AppNavigator navigation={addNavigationHelpers({ dispatch: this.props.dispatch, state: this.props.nav })} /> } }AppWithNavigationState.propTypes = { dispatch: React.PropTypes.func.isRequired, nav: React.PropTypes.object.isRequired, auth: React.PropTypes.object.isRequired, }; const mapStateToProps = state => ({ nav: state.nav, auth: state.auth, }); export default connect(mapStateToProps)(AppWithNavigationState);

答案只需终止所有节点进程并启动npm服务器并运行应用程序:
Step1:运行命令killall -9 node
Step2:运行命令npm start
【Redux connect - 模块AppRegistry不是注册的可调用模块】Step3:运行命令react-native run-ios或react-native run-android

    推荐阅读