208

I am currently going through the React-Native tutorials. I began with the Getting Started tutorial, where I made a new react native project and successfully managed to run the project on my device.

I then started the Props tutorial, I copied the code snippet and tried to run the project again and had the following error message show up on my screen:

eis
  • 51,991
  • 13
  • 150
  • 199
Adam
  • 2,418
  • 3
  • 17
  • 22

30 Answers30

472

I guess it is an error caused by not matching name of project and your registered component.

You have inited project with one name, i.e.

react-native init AwesomeApp

But in your index.ios.js file you register other component

AppRegistry.registerComponent('Bananas', () => Bananas);

When it must be

AppRegistry.registerComponent('AwesomeApp', () => Bananas);

If your component name does match, ensure you don't have any other react-native/node process running in another terminal.

Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116
Slowyn
  • 8,663
  • 3
  • 18
  • 22
  • 7
    "Bananas" some how works for android. But it doesn't on IOS. – Sumit Kushwaha Oct 24 '16 at 13:43
  • 108
    For someone facing same problem even if the component name matches -> Make sure you don't have any other react-native/node process running in another terminal. – Nilesh Nov 04 '16 at 18:00
  • 2
    from my experience, a system reboot sorted the things... as strange as it sounds. – Kayote Dec 19 '16 at 17:25
  • The tutorial is currently called "AwesomeProject" – AdamG Apr 22 '17 at 23:09
  • changing my AppRegistry.registerComponent() from 'AwesomeProject' to 'main' worked for me following this answer https://stackoverflow.com/questions/49410115/application-main-has-not-been-registered – Brandon Culley Apr 11 '18 at 01:39
  • Should we your 7x upvoted comment to the solution answer? @Nilesh – Jonathan Stellwag Apr 13 '18 at 09:50
  • That just might happen if you `eject` from a CRNA codebase and don't use the same app name - that's what I did out of stupidity – neemzy May 07 '18 at 15:33
  • I was ejected my CRNA with a new name, but this line in `index.js`was not renamed. Thanks – Ahmad Behzadi Jul 06 '18 at 14:44
  • 9
    and for people wanting Bananas instead of AwesomeApp can change the `moduleName:@"AwesemeApp"` line in their AppDelegate.m file – Aequitas Oct 03 '19 at 03:05
  • @Kayote , if I judge what Nilesh suggested about another node process running in terminal, then rebooting is the most effective way. In my case I think I have a terminal that popup and ran some react-native process. – KeitelDOG Jun 26 '21 at 16:36
  • appName was correct in `package.json` and Android `MainActivity`. Seems like another terminal launched a process, a MacOs restart fixed it. – KeitelDOG Jun 26 '21 at 17:57
  • In my React Native project, I modified ./app.json -- where the app name is stored. – johnrubythecat Aug 29 '21 at 02:38
52

Modify MainActivity in android/app/src/main/java/com/your-package-name/MainActivity.java like this,

@Override
protected String getMainComponentName() {
    return "Bananas"; // here
}
Raphael Pinel
  • 2,352
  • 24
  • 26
50

Most of the times the problem is that you have another react-native start (i.e. React Native Packager) server running either on another terminal or another tab of TMUX (if you are using TMUX).

You need to find that process and close it, so after running react-native run-ios for instance, it will establish a new packager server that registered for that specific application.

Just find that process using:

ps aux | grep react-native

find the process id (PID) and kill the packager process using kill command (e.g. kill -9 [PID]). You should find the launchPackager.command app in macOS, not sure about the other operating systems.

Then try to run the run-ios (or android) again. You should be able to see the new path after running the new packager server, e.g.:

Looking for JS files in
   /Users/afshin/Desktop/awesome-app 
Afshin Mehrabani
  • 33,262
  • 29
  • 136
  • 201
  • It works, even if I run `react-native start --port `, should I run `react-native run-` in another way?, thanks – Sebastián Palma Mar 02 '17 at 13:21
  • @SebastiánPalma as far as I know, the `start` command runs the packager server so if you have already compiled your application, there is no need to do the `run-`. – Afshin Mehrabani Apr 27 '17 at 08:57
45

My solution is change module name in "AppDelegate.m"

from moduleName:@"AwesomeProject"

to moduleName:@"YourNewProjectName"

user8637708
  • 3,303
  • 2
  • 13
  • 15
  • Yep, that helps me out. An additional hint: If you use XCode, make sure, you have set the right Name to your App-Name (Project -> Target -> DisplayName) – suther Feb 17 '20 at 12:55
  • I had to update my project name on this line ```UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"myNewAppName", nil);```. Basically I did a CTRL+F with my old project name in AppDelegate.m and replaced the one occurrence that I found. This was in addition to changing the bundle identifier and display name xcode – sushrut619 Sep 02 '22 at 14:18
18

First of all you must start your application:

react-native start

Then, you must set your application name as the first argument of registerComponent.

It works fine.

AppRegistry.registerComponent('YourProjectName', () => YourComponentName);
Rafael Ferraro
  • 181
  • 1
  • 3
10

In my case there's this line in MainActivity.java which was missed when I used react-native-rename cli (from NPM)

protected String getMainComponentName() {
    return "AwesomeApp";
}

Obviously ya gotta rename it to your app's name.

xemasiv
  • 111
  • 1
  • 2
9

Please check your app.json file in project. if there has not line appKey then you must add it

{
  "expo": {
    "sdkVersion": "27.0.0",
    "appKey": "mydojo"
  },
  "name": "mydojo",
  "displayName": "mydojo"
}
mperk
  • 324
  • 3
  • 8
9

In index.js you have the following code:-

import {name as appName} from './app.json'; AppRegistry.registerComponent(appName, () => MyApp);

So if in app.json, name is defined as "AwesomeProject" then make sure it same as the following:-

  1. moduleName in ios/projectName/AppDelegate.m :-
    moduleName:@"AwesomeProject"

  2. component name in android/app/src/main/java/MainActivity.java

    @Override
    protected String getMainComponentName() {
    return "AwesomeProject"; // here
    }

mohit arora
  • 592
  • 6
  • 10
  • Thanks, that worked for me after I only changed the app's name in the MainActivity.java for Android and forgot to change it for iOS. – Fabio Dec 18 '21 at 19:42
5

I think the node server is running from another folder. So kill it and run in the current folder.

Find running node server:-

lsof -i :8081

Kill running node server :-

kill -9 <PID>

Eg:-

kill -9 1653

Start node server from current react native folder:-

react-native run-android

Arshid KV
  • 9,631
  • 3
  • 35
  • 36
5

I resolved this by changing the following in the app.json file. It appears the capital letter was throwing this error.

From:

{
  "name": "Nameofmyapp",
  ...
}

To:

{
  "name": "nameofmyapp",
  ...
}
Alex Sarnowski
  • 749
  • 1
  • 11
  • 21
3

I had the same problem and for me the root cause was that I ran (react-native start) the packager from another react-native folder (AwesomeApp), while I created another project in an other folder.

Running the packager from the new app's directory solved it.

László
  • 31
  • 4
3

For me the issue was simple.

Created project a -> everything worked

Created project b -> ran into this error

metro was still running with the work path set to the other application. In my case the solution was as simple as closing the metro process and let it restart

Dbl
  • 5,634
  • 3
  • 41
  • 66
2

This solution worked for me after 2 days of debugging. Change this :

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

to

AppRegistry.registerComponent('main', () => App);
agerxs
  • 66
  • 2
  • 9
1

This can also be due to Root component name starts with lowercase.

Recorrect it or rather create the project once again with a PascalCase name.

e.g. ignite new HelloWord

Venkat
  • 91
  • 8
1

All the given answers did not work for me.

I had another node process running in another terminal, i closed that command terminal and everything worked as expected.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
1

This solved it for me

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

So my index.js file

import { AppRegistry } from 'react-native';
import App from './App';
AppRegistry.registerComponent('main', () => App);

And my package.json file:

"dependencies": {
    "react": "^16.13.1",
    "react-dom": "~16.9.0",
    "react-native": "~0.61.5"
},
0

Rather than changing the name in AppRegistry ,

Run react-native init Bananas , this will create react boilerplate code for Bananas project and AppRegistry.registerComponent will automatically point to bananas

AppRegistry.registerComponent('Bananas', () => Bananas);
abpatil
  • 916
  • 16
  • 20
0

Non of the solutions worked for me. I had to kill the following process and re ran react-native run-android and it worked.

node ./local-cli/cli.js start

G. Thabit
  • 46
  • 5
0

I had the same problem. I was using Windows for creating a react native app for android and was having the same error. Here's what worked.

  • Navigate to the folder ANDROID in your root.
  • Create a file with name : local.properties
  • Open it in editor and write :

sdk.dir = C:\Users\ USERNAME \AppData\Local\Android\sdk

  • Replace USERNAME with the name of your machine.

Save and run the app normally. That worked for me.

0

The issue will also appear when, in index.js, you have named the app differently from the name you gave it for the android/ios package; probably this happened when you've ejected the app. So be sure that when calling AppRegistry.registerComponent('someappname', () => App), someappname is also used for the native packages or viceversa.

Gabriel P.
  • 3,400
  • 2
  • 32
  • 23
0

I figured out where the problem was in my case (Windows 10 OS), but It might also help in Linux as well( You might try).

In windows power shell, when you want to run an app(first time after pc boot) by executing the following command,

react-native run-android

It starts a node process/JS server in another console panel, and you don't encounter this error. But, when you want to run another app, you must need to close that already running JS server console panel. And then execute the same command for another app from the power shell, that command will automatically start another new JS server for this app, and you won't encounter this error.

You don't need to close and reopen power shell for running another app, you need to close node console to run another app.

Shamsul Arefin
  • 1,771
  • 1
  • 21
  • 21
0

After have read all the above, I have found that there could be another reason for this.

In my case:

react-native-cli: 2.0.1

react-native: 0.60.4

and following structure:

enter image description here

First has to be noted that index.android is not been update in Android Studio when the build run by Metro builder( react-native run-android) so it has to be done manually. Also in Android studio does not "read" the

app.json(created by default together with index.js, that renamed index.android.js):

 {
    "name": "authApp",
    "displayName": "authApp"
 }

and so this like

(in my case)

import {authApp as appName} from './app.json';

cause the fact that android studio does not know what authApp refer to. I fix for the moment referring to the app name with its string name and not using that import from app.json:

AppRegistry.registerComponent('authApp', () => MyApp);
Carmine Tambascia
  • 1,628
  • 2
  • 18
  • 32
0

My issue was that in AndroidManifest.xml and MainActivity.java package names were different. So in manifest I had package=com.companyName.appName and in activity package com.appName

Sergiy Ostrovsky
  • 2,372
  • 2
  • 16
  • 23
0

In my case i have got a different solution in case any one need

yarn remove react-native-material-dropdown

Install new packages react-native-material-dropdown-v2

yarn add react-native-material-dropdown-v2

Replace react-native-material-dropdown with react-native-material-dropdown-v2 in your code

e.g. import { Dropdown } from 'react-native-material-dropdown' to import { Dropdown } from 'react-native-material-dropdown-v2'

another thing ==========

  1. Open node_modules and then search for react-native-material-textfield open the file and go to src folder
  2. Under src you will see affix, helper, label folder - under each folder, there is an index.js
  3. open the index.js of the mentioned folders one by one (all 3 folders) and search for the text style: Animated.Text.propTypes.style, and replace it by style: Text.propTypes
  4. And import text form react-native like this import { Animated , Text} from 'react-native';
Wasi Sadman
  • 1,382
  • 1
  • 15
  • 27
0

change name and displayname property in app.json with newer name

amir behrouzi
  • 155
  • 1
  • 10
0

2023 Update:

In your React Native's app, you have a file app.json.

{"name": "AwsomeProject", "displayName": "AwesomeProject" }

"name:" value has to be the same as the root folder's name.

0

I had this error as far as I understand it happened because I opened two projects and ran them by npm run android and that's why it went wrong its cache was not clean what solved it for me was clearing the cache then I closed the emulator and opened a new one and closed both projects and opened the one I wanted And it worked thanks to God

  • I'm sorry, you're right, I'll try to insert punctuation marks. I figured that what happened to me was that I opened two React Native projects, and I ran them both by the command npm run android and that's why I got the error. What solved it was to clear the cache, open a new emulator (in Android Studio, of course) close both projects and open the project I wanted and only run it. It worked for me, thanks to God, I hope it works for you too :) – תמר קופר Apr 28 '23 at 06:42
  • Thanks you for reacting. Are you aware that you can [edit] your post to improve it? Try for [answer] for best results. Have fun. – Yunnosch Apr 28 '23 at 13:50
  • Yes of course, thanks. Did my comment help you? I will be happy to hear! – תמר קופר Apr 29 '23 at 19:48
  • No, anything you only put into a comment does not improve the quality or perceived helpfulness of the answer itself. And since you confirm being aware of the possibiltiy to edit your answer, I am a little puzzled. – Yunnosch Apr 30 '23 at 17:09
0

This error occurred when I changed the app name in App.json. I fixed it by going into android/app/src/main/java/com/ProjectName/MainActivity.java and replacing the new name here:

@Override
  protected String getMainComponentName() {
    return "NewName";
  }

It fixed my problem, I hope it will be helpful to some of you.

-1

you need to register it in index.android.js / index.ios.js

like this:

'use strict';

import {
    AppRegistry
} from 'react-native';

import app from "./app";

AppRegistry.registerComponent('test', () => app);
Reyraa
  • 4,174
  • 2
  • 28
  • 54
linSir
  • 7
  • 3
-1

If you are with expo, you should not change the moduleName in AppDelegate.m and in getMainComponentName(), the default name by registerRootComponent(App) is "main", so it should be remain "main"

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 06 '22 at 09:40