未捕获错误:组件“Privont”尚未在 React Native 应用程序中注册

问题描述 投票:0回答:1

未捕获错误:组件“Privont”尚未在 React Native 应用程序中注册

我在 React Native 应用程序中收到以下错误:

“未捕获错误:‘Privont’尚未注册。如果出现以下情况,可能会发生这种情况:

  • Metro(本地开发服务器)从错误的文件夹运行。检查Metro是否正在运行,在当前项目中停止并重新启动它。
  • 模块由于错误而无法加载,并且未调用
    AppRegistry.registerComponent
    。”

我检查了我的代码,似乎

"Privont"
还没有被注册。这是我迄今为止尝试过的:

  • 重新启动 Metro 捆绑程序。
  • 已验证我正在正确的项目目录中运行 Metro。
  • 检查了我的代码中的
    AppRegistry.registerComponent
    调用。

错误指向第 205 行的

AppRegistry.js

这是我的代码:

1.
index.js

import * as React from 'react';
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import './Core/translations/i18next';
import {Provider} from 'react-redux';
import {PersistGate} from 'reduxjs-toolkit-persist/integration/react';
import {persistedStore, store} from './src/redux/store';

const AppWrapper = () => (
  <Provider store={store}>
    <PersistGate loading={null} persistor={persistedStore}>
      <App />
    </PersistGate>
  </Provider>
);

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

2.
app.json

{
  "name": "Privont",
  "displayName": "Privont"
}

3.
AppDelegate.mm

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  [FIRApp configure];
  // Add this line to call the above function
    ClearKeychainIfNecessary();
  self.moduleName = @"Privont";
  // You can add your custom initial props in the dictionary below.
  // They will be passed down to the ViewController used by React Native.
  self.initialProps = @{};

  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

这是错误图像:参见图像

ios swift react-native
1个回答
0
投票

好吧,我注意到的一件事是,在最后一行的 index.js 中,您正在注册 App,但在使用 AppWrapper 之前

尝试注册它而不是应用程序:

// Register AppWrapper instead of App 
AppRegistry.registerComponent(appName, () => AppWrapper);

还要确保从项目的根目录调用 npm start 或您正在使用的任何命令。

© www.soinside.com 2019 - 2024. All rights reserved.