我在 React Native 应用程序中收到以下错误:
“未捕获错误:‘Privont’尚未注册。如果出现以下情况,可能会发生这种情况:
- Metro(本地开发服务器)从错误的文件夹运行。检查Metro是否正在运行,在当前项目中停止并重新启动它。
- 模块由于错误而无法加载,并且未调用
。”AppRegistry.registerComponent
我检查了我的代码,似乎
"Privont"
还没有被注册。这是我迄今为止尝试过的:
AppRegistry.registerComponent
调用。错误指向第 205 行的
AppRegistry.js
。
这是我的代码:
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);
app.json
{
"name": "Privont",
"displayName": "Privont"
}
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];
}
这是错误图像:参见图像
好吧,我注意到的一件事是,在最后一行的 index.js 中,您正在注册 App,但在使用 AppWrapper 之前
尝试注册它而不是应用程序:
// Register AppWrapper instead of App
AppRegistry.registerComponent(appName, () => AppWrapper);
还要确保从项目的根目录调用 npm start 或您正在使用的任何命令。