javascript - Redux 连接 - 模块 AppRegistry 不是已注册的可调用模块

标签 javascript react-native react-redux react-navigation

在启动新项目并实现 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>
    }
}

据我所知,无需注册我的应用程序类,也无需使用 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 服务器并运行应用程序:

第一步:运行命令killall -9 node

第二步:运行命令npm start

Step3: 运行命令 react-native run-ios 或 react-native run-android

关于javascript - Redux 连接 - 模块 AppRegistry 不是已注册的可调用模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44719363/

相关文章:

reactjs - Typescript React + Redux 中的联合类型出现类型错误时属性不存在

javascript - 将所有 &、<、> 字符转换为 HTML 实体

JavaScript 迭代将数组的值分配给对象

javascript - 未捕获的类型错误 : Cannot call method 'XXX' of undefined

android - 在我的 native react 代码中,keyboardavoiding View 不起作用

reactjs - 为什么react-redux connect不直接将Dumb Component作为参数?

javascript - 如果它有数据但类型或值不正确

javascript - Ant Design Mobile Picker 在 React Native 中使用时不会从底部弹出

javascript - React Native 在按钮单击时将文本添加到 TextInput

reactjs - 如何为React-Redux-Electron JS应用程序创建简单的结构