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 t
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
Modify MainActivity
like this,
@Override
protected String getMainComponentName() {
return "Bananas"; // here
}
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:
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);
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.
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.
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"
},