React Native应用报错:组件'Privont'未注册
React Native 报错:
Uncaught Error: 'Privont' has not been registered 问题详情
应用运行时触发错误:Uncaught Error: 'Privont' has not been registered,错误定位在AppRegistry.js第205行。
已知可能诱因:
- Metro开发服务器运行目录错误,需在项目根目录重启Metro;
- 模块加载失败,未正确调用
AppRegistry.registerComponent。
已执行的排查步骤:
- 重启Metro bundler;
- 确认Metro运行目录为项目根目录;
- 检查
AppRegistry.registerComponent调用逻辑,确认代码已正确实现。
但问题仍未解决。
相关代码片段
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, () => AppWrapper);
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]; }
额外排查建议
- 检查Redux Persist导出项:确认
./src/redux/store中是否正确导出persistor(Redux Toolkit Persist标准导出名称为persistor,而非代码中的persistedStore,名称不匹配可能导致组件渲染失败); - 清理全量缓存:
- 执行
npx react-native start --reset-cache重启Metro并清除缓存; - iOS端:删除项目根目录
Pods文件夹,执行pod install,再通过Xcode执行Product -> Clean Build Folder清理构建缓存; - Android端:在
android目录下执行./gradlew clean清理构建缓存;
- 执行
- 检查
App组件完整性:确认./App.js无语法错误、导入错误或未捕获的异常,避免AppWrapper无法正常渲染; - 确认注册逻辑执行顺序:保证
AppRegistry.registerComponent为index.js中最后执行的逻辑,避免异步操作(如i18n初始化)阻塞组件注册流程。
内容的提问来源于stack exchange,提问作者Ravi Gaud
相关产品推荐
相关产品推荐

