Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application main has not been registered

I have recently started to convert my react native app and running on Expo so i could test this on my actual android device. I am getting this error above. I have since then running my app using the Expo XDE. I am also running on a windows machine.

The full error message is:

enter image description here]1

I figured that this has something to do with my index.js, yet here it is

import { AppRegistry } from 'react-native';
import App from './App';

AppRegistry.registerComponent('projectTARA', () => 'App');
like image 311
johnobc Avatar asked Mar 21 '18 15:03

johnobc


People also ask

Has not been registered this can happen if?

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.

What is AppRegistry registerComponent?

AppRegistry is the JS entry point to running all React Native apps. App root components should register themselves with AppRegistry. registerComponent , then the native system can load the bundle for the app and then actually run the app when it's ready by invoking AppRegistry. runApplication .

What is index JS in react native?

js file in the root of your React Native project. index. js is the starting point for React Native applications, and it is always required. It can be a small file that require s other file that are part of your React Native component or application, or it can contain all the code that is needed for it.


2 Answers

The following solution worked:

AppRegistry.registerComponent('main',() => App);

Credits: Rishav Kumar

(Cannot you people just reply to mark as solve ?)

like image 140
ATX Avatar answered Oct 04 '22 03:10

ATX


I came across this issue because I had previously run a React project that was not fully shut down. To fix this, I could have restarted my computer. But I chose to do this instead: (Using MacOS, should work with Linux as well, for Windows you would likely need to use Task Manager or similar):

  1. Open terminal
  2. Find the program that is using port 8081 by typing "lsof -i :8081". (Note this is LSOF in lowercase)
  3. Look at the process ID (under the PID column)
  4. Kill the process by typing "kill -9 PID" (where PID is the process ID number you found in step 3).

After killing the process you should be able to run your react-native project.

like image 21
kojow7 Avatar answered Oct 04 '22 04:10

kojow7