React-Native:模块AppRegistry不是注册的可调用模块


114

我目前正在尝试让ES6 react-native-webpack-server在Android模拟器上运行。不同之处在于我已经升级了我的产品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.
乔什·费拉拉

Answers:


58

0.18.1今天刚升级为React-native ,但0.19.0-rc预发行版本存在一些同级依赖问题。

回到您的问题,我所做的是

  1. cd android
  2. sudo ./gradlew clean(有关清洁的更多信息,请点击此处

然后回到工作目录并运行 react-native run-android

升级后,您也应该重新启动npm。

希望这对您有用。


3
我正在尝试运行gradlew命令,但它始终告诉我即使我ANDROID_HOME在路上也找不到Android SDK 。我还用添加了local.properties文件sdk.dir=。有任何想法吗?
steezeburger '16

42
当给出建议进行类似操作时sudo ./gradlew clean,很高兴地提到这是一个巨大的操作,显然可以重新下载并重新安装整个gradle发行版。
SzczepanHołyszewski16年

1
出现错误模块HMRClient不是注册的可调用模块(调用启用)。我看不到我在js文件中所做的更改:(
Dinesh R Rajput,2016年

要找到您的Android SDK位置,请打开Android Studio并单击“配置”,您会在顶部看到一条路径,该路径可能类似于:/Users/karim/Library/Android/sdk
Karim Mortabit

在我尝试更新为RN 0.44之后,这对我没有任何帮助
SleepsOnNewspapers

15

我在iOS上遇到了同样的问题,原因是我的index.ios.js不正确(因为我复制粘贴了其中一个示例,而没有查看其内容),它以模块导出声明结尾

exports.title = ...
exports.description = ...
module.exports = MyRootComponent;

而不是预期的

AppRegistry.registerComponent('MyAppName', () => MyRootComponent);

我猜你可能在Android上使用index.android.js遇到同样的问题。


13

出现此问题的一个主要原因可能是在哪里安装了插件而忘记了链接它

试试这个:

react-native link

重新运行您的应用。

希望这会有所帮助。请在评论中让我知道。谢谢。


1
react-native link不建议使用没有包名称的运行,它将在下一发行版中删除。
Harshad Madaye,

9

我通过添加解决了这个问题

import { AppRegistry } from "react-native";
import App from "./App";
import { name as appName } from "./app.json";  
AppRegistry.registerComponent(appName, () => App);

到我的index.js

确保它存在于您的index.js中


3

对我来说,我的问题是捆绑时放入错误的入口文件

我使用App.js作为输入文件,因此该应用找不到AppRegistry

正确:

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

不正确:

react-native bundle --platform android --dev false --entry-file App.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

您省了我的脑筋...几天 以来,我一直在试图理解为什么我启动该命令: react-native bundle --platform android --dev false --entry-file index.js --bundle-output android /app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res 一切正常,而如果我使用fastlane发布,则该应用程序因以下错误Module AppRegistry is not a registered callable module (calling runApplication)而崩溃: 在build.gradle中,我可能有污垢,错误的entryFile!再次感谢!
Nobady

3

希望这可以减轻某人的头痛。升级我的本机版本后,出现此错误。令人困惑的是,它仅出现在事物的android方面。

我的文件结构包括index.ios.jsindex.android.js。两者都包含代码:

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

我要做的是android/app/src/main/java/com/{projectName}/MainApplication.java更改indexindex.android

@Override
protected String getJSMainModuleName() {
    return "index.android"; // was "index"
}

然后在app/build/build.gradle,改变entryFileindex.jsindex.android.js

project.ext.react = [
    entryFile: "index.android.js" // was index.js"
]


2

我不知道为什么,但是当我从index.android.js包含的index.js文件中移动AppRegistry.registerComponent来直接驻留在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

我在Genymotion上将其卸载。然后运行react-native run-android以构建应用程序。而且有效。在运行之前先尝试一下sudo ./gradlew clean,这样可以节省很多时间。



1

如果您在Windows中使用Android遇到此错误

打开您的根目录app文件夹,然后移至android文件夹。

     cd android 
     gradlew clean

再次启动您的应用react-native run-android

糟糕


0

就我而言,我index.js只是错误地指向了另一个js而不是我的Launcher js,其中不包含AppRegistry.registerComponent()

因此,请确保该文件是您index.js注册课程的重点。


0

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

sudo sysctl fs.inotify.max_user_watches=1280000

0

对我来说,这是一个问题,它依赖于下一个版本的react软件包,而在我的package.json中指定了旧版本。升级我的反应版本解决了这个问题。


0

对我来说,我以这种方式与react native链接:react-native链接


也许在这一点上扩大一点。

0

npm start--重置缓存

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


0

我在Expo中收到此错误,因为我导出了错误的组件名称,例如

const Wonk = props => (
  <Text>Hi!</Text>
)

export default Stack;


0

如果您使用的是Windows机器,你需要做的cd android,然后./gradlew clean再运行react-native run-android

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.