You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Expo项目报错:"main"组件未注册(Invariant Violation)

Expo React Native 遇到 Invariant Violation: "main" has not been registered 报错

3492ms ERROR Invariant Violation: "main" has not been registered

报错提示的可能原因:

  • Metro(本地开发服务器)运行目录错误,需检查并在当前项目重启;
  • 模块加载失败导致未调用AppRegistry.registerComponent,js引擎:hermes

已完成的排查操作:

  • 核对代码确认AppRegistry.registerComponent调用正确;
  • 清理Metro缓存、重启服务器;

问题仍未解决,怀疑存在依赖冲突或项目配置错误,以下是相关文件的简化版本:

相关文件代码

package.json

{
  "name": "cbdcexpress",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@expo/vector-icons": "^13.0.0",
    "@react-navigation/bottom-tabs": "^6.5.8",
    "@react-navigation/native": "^6.1.7",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native-elements": "^3.4.3",
    "react-native-gesture-handler": "^2.12.1",
    "react-native-paper": "^5.10.1",
    "react-native-qrcode-scanner": "^1.5.5",
    "react-native-reanimated": "^2.2.4",
    "react-native-screens": "^3.24.0",
    "react-scripts": "5.0.1",
    "web-vitals": "^2.1.4"
  },
  // ... rest of the package.json
}

index.js

import React from 'react';
import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';

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

app.json

{
  "expo": {
    "name": "CBDCExpress",
    "slug": "cbdc-express",
    "version": "1.0.0",
    "icon": "./assets/icon.png",
    "sdkVersion": "49.0.0",
    "platforms": [ "android", "ios" ],
    "description": "Central Bank Digital Currency Express App",
    "androidStatusBar": {
      "backgroundColor": "#2196F3",
      "barStyle": "light-content"
    },
    "ios": {
      "supportsTablet": true
    }
  }
}

app.js

import React from 'react';
import AppNavigator from './navigation/AppNavigator';

export default function App() {
  return <AppNavigator />;
}

内容的提问来源于stack exchange,提问作者Rapidhunter

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 12:15:20