React-Native:模块AppRegistry未注册为可调用模块

160
我目前正在尝试在Android模拟器上运行ES6 react-native-webpack-server。不同之处在于,我已经升级了我的package.jsonbuild.grade以使用react 0.18.0,并且在启动时遇到了此错误。据我所知,AppRegistry已正确导入。即使我注释掉代码,此错误仍会出现。这在iOS上没有问题。

我错在哪里?

编辑:尝试其他支持0.18.0的样板文件后,我仍然遇到相同的问题。

进入图像描述


我在0.19和0.20版本中遇到了同样的问题,尝试了所有方法但都没有成功。@Dustin有任何更新吗? - Shprink
@Shprink 我也遇到了0.20的这个问题。同时收到了这个错误信息 One of the sources for assign has an enumerable key on the prototype chain. - Josh Ferrara
30个回答

2

重新启动打包器 对我有用。 只需终止React Native打包器并再次运行即可。


2

请使用以下包:

"react-native-reanimated": "^2.2.4",


2

我不知道为什么,但当我将AppRegistry.registerComponent从index.js文件移动到直接包含在index.android.js中时,它似乎可以工作。


1
如果您使用了一些示例,它们可能无法正常工作。
这是我对滚动视图的版本。
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */

import React, {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  View,
  ScrollView,
  TouchableOpacity,
  Image
} from 'react-native';

class AwesomeProject extends Component {
  render() {
    return (
        <View>
          <ScrollView
            ref={(scrollView) => { _scrollView = scrollView; }}
            automaticallyAdjustContentInsets={false}
            onScroll={() => { console.log('onScroll!'); }}
            scrollEventThrottle={200}
            style={styles.scrollView}>
            {THUMBS.map(createThumbRow)}
          </ScrollView>
          <TouchableOpacity
            style={styles.button}
            onPress={() => { _scrollView.scrollTo({y: 0}); }}>
            <Text>Scroll to top</Text>
          </TouchableOpacity>
        </View>
    );
  }
}

var Thumb = React.createClass({
  shouldComponentUpdate: function(nextProps, nextState) {
    return false;
  },
  render: function() {
    return (
      <View style={styles.button}>
        <Image style={styles.img} source={{uri:this.props.uri}} />
      </View>
    );
  }
});

var THUMBS = [
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1,
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1,
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1
];

THUMBS = THUMBS.concat(THUMBS); // double length of THUMBS
var createThumbRow = (uri, i) => <Thumb key={i} uri={uri} />;

var styles = StyleSheet.create({
  scrollView: {
    backgroundColor: '#6A85B1',
    height: 600,
  },
  horizontalScrollView: {
    height: 120,
  },
  containerPage: {
    height: 50,
    width: 50,
    backgroundColor: '#527FE4',
    padding: 5,
  },
  text: {
    fontSize: 20,
    color: '#888888',
    left: 80,
    top: 20,
    height: 40,
  },
  button: {
    margin: 7,
    padding: 5,
    alignItems: 'center',
    backgroundColor: '#eaeaea',
    borderRadius: 3,
  },
  buttonContents: {
    flexDirection: 'row',
    width: 64,
    height: 64,
  },
  img: {
    width: 321,
    height: 200,
  }
});

AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

1

npm start -- --reset-cache

可能端口已被使用。当我第一次运行react-native run-android然后运行npm start时,我遇到了类似的问题。我像这样解决它:首先,获取在端口8081上运行的进程的ID:

sudo lsof -i :8081


1

我曾多次遇到同样的问题。以下解决方案解决了我的问题。我根据复杂程度列出了它们。

  1. Restart the computer and see whether the problem is out

  2. If it still exists, try to kill the process on running port usually 8080

    netstat -ano | findstr 8080

     taskkill /F /PID <PID>
    
  3. If it still exists, go to 'android' directory as follow and go further

    cd android

    ./gradlew clean

并启动节点

npm start

然后运行npx react-native run androidexpo stat,并按下'a'

希望您对上述问题满意。


1

我遇到的问题通过以下命令得到解决(操作系统:Windows 10)。

  1. cd android
  2. gradlew clean
  3. cd..
  4. npx react-native run-android

1

我曾遇到过同样的问题,那是因为我在没有导入的情况下调用了样式表。


目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何编写好答案的更多信息。 - Community

1
我在Genymotion上卸载了它。然后运行react-native run-android来构建应用程序。这样做是有效的。在运行sudo ./gradlew clean之前,请先尝试这个方法,这将为您节省大量时间。

0

我的问题通过增加inotify max_user_watches得到了解决:

sudo sysctl fs.inotify.max_user_watches=1280000

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接