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

我使用本地基础,使应用程序在反应本地。这两件事我都是新手。当我运行这个应用程序时,它会给我一个错误:

enter image description here

这是我的代码:

export default class Point extends Component {


render() {
return (
<Container>
<Header>
<Left>
<Button transparent>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title>Header</Title>
</Body>
<Right />
</Header>
</Container>
);
}
}

这是我的版本的截图

enter image description here

本地版本是 "native-base": "^2.1.2"

246793 次浏览

You should have this at the bottom of the index.ios.js file AppRegistry.registerComponent('Point', () => Point); 并从 react-native导入 AppRegistry

我是使用本地的基础,我的应用程序在这里是链接 native base

你可以看到没有像这样的应用程序注册表

 AppRegistry.registerComponent('Point', () => Point)

但我必须这么做才能运行我的应用程序

只需杀死所有节点进程,启动 npm 服务器并运行应用程序:

步骤1: 运行命令 killall -9 node

对于 windows 用户,运行: taskkill /im node.exe

如果进程仍然存在,则运行 taskkill /f /im node.exe

步骤2: 运行命令 npm start --reset-cache

步骤3: 运行命令 react-native run-iosreact-native run-android

需要更换

.setJSMainModulePath("index") with .setJSMainModulePath("index.android")

For me, restarting my computer appears to be enough to clear this issue.

在使用 git 在分支或合并分支之间切换之后,通常需要使用这个函数。

我有这个问题-这是奇怪的,因为我重置我的回购时,应用程序正在工作的时间。问题出在我的模拟器(iOS)上。

对我来说,解决办法就是

  1. 终止模拟程序(退出)
  2. 然后-关闭终端窗口打开时,模拟器运行(地铁捆绑器) 终端窗口的图像

发生这种情况的原因之一是:-

  • 或者,您的应用程序的条目文件“ index.js”由于语法错误而损坏,或者您的 React 应用程序无法加载。
  • Your Metro Bundler instance running is stale and corrupt.

解决方案

  • 终止已经运行的 Metro Bundler实例

  • 重置缓存

    react-native start --reset-cache
    
  • 删除 android/app/bulid文件夹

  • 重启服务器

关闭当前的 Metro Bundler,通过重置缓存来重新启动,这对我来说很有效

npm start -- --reset-cache
import { AppRegistry } from 'react-native';


AppRegistry.registerComponent('your app name',  () => point);

Close the current Metro Bundler and restart by typing the comment:

npm start -- --reset-cache

只是关闭了地铁捆绑,重建了应用程序完成了我的工作。

为我工作的以下版本和 iOS:

"react": "16.9.0",
"react-native": "0.61.5",

解决问题
关闭正在运行的 Metro Bundler
尝试重新运行 Metro Bundler 并检查此问题是否仍然存在

Stop the node server running and run 'react-native run-ios' once again.

  1. 关闭模拟器

  2. Npm 启动——重置-缓存

  3. XCode-> Product-> Clean Build 文件夹

  4. Npx response-本机 run-ios

如果你使用窗户和纱线 open cmd on admin mode' 通过键入以下命令终止并重新启动节点进程。

查找节点: kill all -9节点 强制删除: taskkill/f/im node.exe 重置缓存: 纱线开始——重置缓存

Navigate to your project directory: cd myapp 重新运行你的应用程序: 纱线机器人

使用以下命令清除缓存:

react-native start --reset-cache

您只需要通过 控制 + c关闭地铁服务器,然后通过 Npm 启动——重置缓存重新启动

注意 : 如果这个也不起作用,那么重新启动你的计算机,它一定会起作用的。

在我的情况下,尝试 npm start -- --reset-cache和得到一堆更多的错误,我删除(卸载)的应用程序从 iOS 和 Android 和 yarn ios yarn android做的诀窍。

在我的例子中,我没有在组件中导入正在使用的模块。

所以,只需检查是否正在导入要使用的模块..。

我在终端机试了 killall -9 node命令

then again i run my project using npm start and it's working fine

其中一个库没有链接。 To check, just comment out in the package.json one by one the latest libraries added.

纱线去除库名称。

然后用 xcode 和 puf 运行应用程序!

解决方案非常简单,只需杀死所有正在运行的节点,重新启动节点服务器并重新构建本机应用程序,就可以了。

对于 Linux:

killall -9 node

视窗:

taskkill /im node.exe

对于 Android 本地应用程序:

react-native run-android

For IOS native App:

react-native run-ios

最后,

npm start

我也为 Windows 操作系统遭遇了同样的错误。我通过清理 gradlew解决了这个问题。

步骤如下:

  1. cd android
  2. gradlew clean
  3. cd..

在安装了一个包含一些需要安装的本机代码的新软件包之后,我往往会得到这个错误。通常包会说安装 npm 模块,然后通过 pod 安装(ios 特定)安装本机代码,在这之后,我的应用程序通常会抛出这个错误。

为了摆脱这个错误,我删除并重新安装 node _ module 和 pods,因为我正在制作一个 iOS 应用程序,然后我还删除了 iOS 下的 build 文件夹。之后,我使用 npm start ——重置缓存运行这个打包器,并使用 response-national run-ios 命令再次构建我的应用程序。这就解决了我的问题。

在计算机重启和删除/重建 npm_modules文件夹、 Pods文件夹和我的 ios 构建文件夹之后,我最终创建了一个全新的反应本机项目。(退出模拟器,退出终端应用程序,退出 XCode,清理 XCode 中的项目文件夹,运行 killall -9 nodenpm start -- reset-cahcenpm start -- --reset-cache也不起作用)。安装完所有软件包后,我将代码从旧项目复制粘贴到新项目。同样的错误。所以我开始一步一步地回溯我最近的代码更改。在恢复了我最近的代码更改之后,它工作了。在一点一点地添加新代码时,我得到一个错误,告诉我我忘记了 import {StyleSheet} from 'react-native';。我导入了它,然后继续添加之前导致错误的代码(只是一个 react-native-elementsButton和一个 StyleSheetconst styles)。一切顺利。

所以,最后,我唯一的理论是,我一次性添加了太多的代码,而不是告诉我我忘记了 import {StyleSheet},因为它应该有,而是抛给我一个模糊和令人恼火的 module AppRegistry错误。

如果您正在构建一个新的 Npm 模块,并且这依赖于已经添加到项目中的其他依赖项,那么您需要将这些依赖项作为对等依赖项添加到 npm 包的 package.json 中。

package.json

"peerDependencies":{
"@org/your-dependency":">= 1.2.0"
}
[Tue Aug 31 2021 17:57:45.731]  ERROR    Error: Type oid already present, js engine: hermes
[Tue Aug 31 2021 17:57:45.732]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication), js engine: hermes
[Tue Aug 31 2021 17:57:45.732]  ERROR    Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication), js engine: hermes

对我来说,问题是在我的一个样式出现错误时启动 Metro 捆绑包。昨晚我的代码出错了然后我的电脑一夜之间就重启了。今天尝试启动所有程序会导致这个错误以及 Invariant Violation: Invalid prop 'position' of value 'fixed' supplied to。修复 position值解决了这两个错误。

npm start -- --reset-cache

本地人的反应

我没问题。

一个单一的错误,但可能有多个原因。在社区中看到许多不同的讨论意味着这个问题可能很难找到。尝试执行以下操作。

  1. 可能少了一个进口货。
  2. 您最近安装的库可能缺少配置。
  3. 在 Android 系统中可能不会收到错误,但是在 IOS 系统中会收到错误。
  4. 如果 RN 升级了,您的缓存需要重置。

If you still cannot find the issue with the above, remove some imports or screens from your App.js. Going with this you can find what exactly caused this error. This is how I found my issue after a day of research.

点击查看更多 Github 问题

关闭当前的城市捆绑包并运行以下命令:

npm start -- --reset-cache

delete node_modules and install it again using npm i 然后应用这个命令 Npm 启动——重置-缓存

除了以上所有内容之外,值得尝试在 redux存储目录的某个地方找到并注释掉以下代码:

.concat(composeWithDevtools)

它帮我解决了问题。