module appregistry is not a registered callable mo

2019-08-20 12:09发布

问题:

i cannot find a way to make react-navigation work at all. i copied the working examples from the internet but they don't seem to work too. can someone tell me what i am doing wrong.

i'm using node: 8.9.4 react: 16.3.0-alpha.1 react-native: 0.54.0 react-navigation: ^1.4.0

//index.js
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';
import {
  TabNavigator,
  StackNavigator
} from 'react-navigation';

import Home from './first';
import Homes from './second';

export default class demoApp extends Component {
  render() {
    return (
      <SimpleNavigation/>
    );
  }
}

export const SimpleNavigation = StackNavigator({
  Home: { 
    screen: Home,
    header: { visible: false },
    navigationOptions: {
      title: 'Home',
      header: null
    },
  },
  Homes: { 
    screen: Homes,
    navigationOptions: {
      title: 'second'
    },
  },
},{});

Here's the first tab

//first.js
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image,
  TextInput,
  Button,
  TouchableHighlight
} from 'react-native';

export default class Home extends Component {
    constructor(props){
        super(props);
        this.state = {zipCode: ''}
    }
    navigate = (zipCode) => {
        this.props.navigation.navigate('Search', zipCode);
    }
    render() {
        return (
            <View>
                <View>
                    <Text>An application to do things</Text>
                    <TextInput 

                        placeholder='Enter a Zip Code' 
                        onChangeText={(zipCode) => this.setState({zipCode})}
                        >
                    </TextInput>
                </View>
                <View>
                    <TouchableHighlight onPress={() => this.navigate(this.state.zipCode)}>
                        <Text>
                            Search
                        </Text>
                    </TouchableHighlight>
                </View>
            </View>
        );
    }
}

i cant seem to make it run at all. I tried following many other tutorials as well. But none of them worked. What am i doing wrong?

回答1:

I kept getting this error too today, and it was very annoying. Was able to get rid of it by removing the Terminal window with "Metro" bundler stuff, and then recompiling the app.

Seems like it's not the code, but rather the runtime environment (which seems to work well with only one app example at a time). You can double check this by doing a super simple app that should work.



回答2:

Just kill all node process and start npm server and run application:

Step1: run command killall -9 node

Step2: run command npm start

Step3: run command react-native run-ios OR react-native run-android



回答3:

Close your Nodejs Terminal and run again