Skip to content
FR
  1. LuzineDebug
  2. Mobile (Android, iOS)
  3. Invariant Violation: "main" has not been registe…
Mobile (Android, iOS) Beginner ≈ 10 min to fix

Fix "Invariant Violation: "main" has not been registered" (React Native / Expo)

Error message
Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
  • ERROR Invariant Violation: "MyApp" has not been registered. This can happen if:
  • Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
  • Application MyApp has not been registered. This is either due to a require() error during initialization or failure to call AppRegistry.registerComponent.
  • Invariant Violation: "main" has not been registered. This can happen if: * Metro (the local dev server) is run from the wrong folder.
In short

The native app asked for a root component named main (or your app name), but the JavaScript bundle never registered it. First look for the error that appears right before (a failing import), check that the name passed to AppRegistry.registerComponent matches the one in native code, then restart a single Metro with --reset-cache.

Be the first to confirm this fix

What this error means

At startup, the native side (MainActivity on Android, AppDelegate on iOS) loads the JavaScript bundle and asks AppRegistry to run the component with a given name: main for Expo, the name from app.json for bare React Native. That component must have been registered by the entry file through AppRegistry.registerComponent or Expo registerRootComponent. If the entry file crashed before that call, if the name does not match, or if the app received another project bundle served by another Metro, no component exists under that name and React Native throws this Invariant Violation. It is almost always the symptom of another error.

Common causes

  1. Error while loading a module: a missing import, a top-level exception or a missing native module ("could not be found") stops the entry file before registerComponent.
  2. Different names: app.json says MyApp, but getMainComponentName() (Android) or the AppDelegate moduleName (iOS) expects another name, often after renaming the project.
  3. Wrong Expo entry point: the main field in package.json points to a file that does not call registerRootComponent, or is not expo-router/entry with Expo Router.
  4. Metro from another project: a Metro started in another folder already holds port 8081 and serves its own bundle to your app.
  5. Stale Metro cache after an upgrade, an entry point change or a Babel configuration change.

Step-by-step fix

  1. Find the first error

    Scroll up in the Metro terminal and in LogBox: the real error (module not found, undefined is not a function, missing native module) is printed before "has not been registered". Fix it first.

  2. Check the entry file (React Native)

    The index.js file must register the root component with the name defined in app.json.

    javascript
    import { AppRegistry } from 'react-native';
    import App from './App';
    import { name as appName } from './app.json';
    
    AppRegistry.registerComponent(appName, () => App);
  3. Check the entry point (Expo)

    With Expo, registerRootComponent registers the component under the name main. The main field in package.json must point to that file, or to expo-router/entry if you use Expo Router.

    javascript
    // index.js
    import { registerRootComponent } from 'expo';
    import App from './App';
    
    registerRootComponent(App);
    
    // package.json: "main": "index.js"
    // with Expo Router: "main": "expo-router/entry"
  4. Compare with the native name

    Bare React Native project: the name returned by getMainComponentName() and the one in the AppDelegate (moduleName or withModuleName) must match the name in app.json. Fix one side or the other, then rebuild the native app.

    bash
    grep '"name"' app.json
    grep -rn "getMainComponentName" android/app/src/main
    grep -rn "moduleName" ios/*/AppDelegate*
  5. Stop other Metro instances

    Check what holds port 8081 and stop that process if it belongs to another project.

    bash
    # macOS / Linux
    lsof -i :8081
    kill <PID>
    
    # Windows (PowerShell)
    netstat -ano | findstr :8081
    taskkill /PID <PID> /F
  6. Restart Metro without cache and relaunch the app

    Start Metro from the project root with its cache cleared, then reload the app (r key) or rebuild it if you changed native code.

    bash
    # React Native
    npx react-native start --reset-cache
    npx react-native run-android
    
    # Expo
    npx expo start -c

Did this fix work for you?

Confirm it in one click: it will rise for the next developers stuck on the same error.

Keep it from coming back

  • To rename a React Native app, change the name in app.json, in MainActivity and in the AppDelegate together, then rebuild; with Expo, let registerRootComponent handle the main name.
  • Stop Metro when you switch projects, or run each project on its own port with --port.
  • Keep the entry file minimal: avoid code that can crash at module level before registerComponent.

Frequently asked questions

Why "main" when my app has another name?

Expo (and projects generated with expo prebuild) always use the component name main. In a bare React Native project, the message shows the name set on the native side, for example "MyApp" has not been registered.

Why does the error only appear in release?

In release, the bundle is embedded in the app: an error while loading (missing environment variable, unlinked native module) prevents registration. Read the logs with adb logcat or the Xcode console to find the original error.

Should I run expo prebuild --clean?

Only if the generated native code is out of sync with your configuration. This command regenerates android/ and ios/ and erases any manual native changes: commit first.

Useful tools for this error

More Mobile (Android, iOS) errors

All Mobile (Android, iOS) errors →