反应-本机: 模块 AppRegistry 不是注册的可调用模块

我现在正试着让 ES6的反应-本机-webpack-服务器运行起来 在 Android 模拟器上。区别在于我已经升级了我的 package.jsonbuild.grade,使用了反应 0.18.0,并且在引导时得到了这个错误。据我所知,AppRegistry是正确导入的。即使我注释掉代码,仍然会出现这个错误。这在 iOS 上没有问题。

我做错了什么?

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

enter image description here

262914 次浏览

我刚刚升级到反应-原生 0.18.1今天艰难有一些对等依赖问题与 0.19.0-rc预发布版本。

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

  1. cd android
  2. sudo ./gradlew clean(更多关于清洁工作的信息

然后跑回工作目录 react-native run-android

在升级之后你也应该重新启动你的 npm。

希望这对你有用。

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

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

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

而不是期望中的

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

我想,在 android 上 index.android.js 也会有同样的问题。

如果您使用的是其中的一些示例,那么它们可能不起作用

这是我的滚动视图版本

/**
* 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);

我把它卸载到 Genymotion 上了。然后运行 react-native run-android来构建应用程序。而且成功了。在运行 sudo ./gradlew clean之前,请先尝试一下,这样可以节省很多时间。

希望这能给某人省点麻烦。在升级我的本地反应版本之后,我得到了这个错误。令人困惑的是,它只出现在机器人的一面。

我的文件结构包括一个 index.ios.js和一个 index.android.js。它们都包含代码:

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

我要做的是,在 android/app/src/main/java/com/{projectName}/MainApplication.java中,把 index改成 index.android:

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

然后在 app/build/build.gradle中,将 entryFileindex.js改为 index.android.js

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

在我的例子中,我的 index.js只是错误地指向另一个 js 而不是我的 Launcher js,因为它不包含 AppRegistry.registerComponent()

因此,确保文件的 index.js点注册类。

通过增加 inotify max _ user _ watch,我的问题得到了解决:

sudo sysctl fs.inotify.max_user_watches=1280000

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

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

我使用 App.js 作为输入文件,因此 App 无法找到 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/

我解决这个问题只需要加上

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

到我的 Index.js

确保这存在于你的 Index.js

一个主要的 这个问题的原因可能是 你会安装一个插件而忘记链接它

试试这个:

react-native link

重新运行你的应用程序。

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

对于我来说,我只是以这种方式链接到本地反应: 本地反应链接

重新启动包装程序 对我来说很管用。 只要杀死反应本地包装,并再次运行它。

对我来说只要重新启动电脑就能修好。 (我的错误是“ module appRegistry 不是注册的可调用模块(调用 runapplication) js engine: hermes”)

这里缺少的另一个可能有效的解决方案是杀死节点进程:

killall -9 node

[ 模块 AppRegistry 未注册可调用模块(调用 runApplication)]

如果您在 android 窗口中遇到此错误

打开您的根目录应用程序文件夹并移动到 android 文件夹。

cd android
gradlew clean

再次启动你的应用程序

react-native run-android

Npm 启动——重置-缓存

可能端口已经在使用了。我面临类似的问题时,我第一次运行的反应-本机运行-机器人,然后 npm 启动。我是这样解决的: 首先,获取在端口8081中运行的进程的 id: 苏多伊索夫-i: 8081

我在 Expo 中得到了这个错误,因为我导出了错误的组件名,例如。

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


export default Stack;

我通过以下方法解决了这个问题:

  1. CD 机器人
  2. 。/格拉德罗干净
  3. Taskkill/f/im node.exe
  4. 从安卓卸载应用程序

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

当我在 node_modules目录中摆弄依赖项的代码时,我遇到了这个问题——在 iOS 和 Android 上,在 Mac 上进行开发。

我用以下方法解决了这个问题:

rm -rf node_modules
npm i
npx pod-install ios

它基本上只是重新安装您的依赖项。

我好几次都遇到同样的问题。下面的解决方案解决了我的问题。我已经根据复杂程度把它们列出来了。

  1. 重新启动计算机,看看问题是否出来了

  2. 如果它仍然存在,尝试在运行端口(通常是8080)上终止进程

    Netstat-ano | findstr 8080

     taskkill /F /PID <PID>
    
  3. 如果它仍然存在,按照下面的步骤进入“ android”目录

    CD 机器人

    。/格拉德罗干净

并启动节点

npm start

然后运行 npx react-native run androidexpo stat并按“ a”

希望你能接受上述问题。

这可能是因为任何缓存问题从节点,吊舱,梯度任何地方,其更好的是做一个完整的清理板块,为此使用 反应本地清洁工程

检查是否在 SafeAreaView 中没有直接呈现某些内容

请确保遵循此格式

<SafeAreaView>
<View>
{children}
</View>
</SafeAreaView>

通过以下命令(OS: Windows10) ,我的问题得到了解决。

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

请使用下面提到的: 包装

“反应-本地-复活”: “ ^ 2.2.4”,

我得到这个错误的一个典型原因是当我导入错误的组件时(比如导入了错误的名称)。如果我输出得不好,他们正确地输入,也是一样的。这可能看起来很原始,但犯错是人为的,很多时候这个错误出现,如果清理项目并重新启动它不能修复它,它可以是这个。

删除 android/. gradle 和 reac-module。 而不是运行纱线安装和运行机器人

import * as React from 'react';
import { Button, Text, View } from 'react-native';


function Home() {
return (
<View style=\{\{ flex: 1, alignItems: 'center', justifyContent: 'center',backgroundColor:'red'}}>
<Text>hiiiiiiiiiiiiiii</Text>
</View>
);
}


export default Home; <--- cheack this line

我也有同样的问题,因为我调用样式表时没有导入. 。

在 iOS 上,我遇到了这个问题。

但是在清理建筑物之后 通过输入 command + shift + k 并再次构建该文件夹对我来说很有效

你也应该检查方案应该被调试