'EAS Build (Android) .apk Crashes, Expo Build .apk Runs Correctly

I'm updating a React Native app to EAS Build, after using expo build for several years. The app works via the development server.

After running eas build, the .apk file builds successfully, but immediately crashes when opened on a device.

My error log is:

TypeError: undefined is not an object (evaluating 't.indexOf')
Running "main" with {"rootTag":1}
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.

Has anyone run into this error?



Solution 1:[1]

i have the same problem

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.

Solution 2:[2]

I also had problems, but after reading the documentation some things changed.

  1. Are you migrating an Expo managed app from "expo build"? Learn about the differences.

  2. They must create an index file (reference), with:

    import { registerRootComponent } from 'expo';
    import App from './src/App';
    
    registerRootComponent(App);
    

    (If the App.js is in the root, delete the /src so they have ./App)

    And then, from the package.json, delete the entire line of main.

  3. And [this is the most difficult step] (https://docs.expo.dev/build-reference/migrating/#metroconfigjs--must-export-the-entire-default

, it cost me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Munawar Kholil
Solution 2