New to React Native: I started a brand new project with Expo init and then I followed the instructions mentioned inhttps://reactnavigation.org/docs/hello-react-navigation I run the project with expo start and I get this error. Invariant Violation: "main" has not been registered. This can happen if:
AppRegistry.registerComponent
wasn't called.invariant browser.js:38:14 runApplication AppRegistry.js:193:13 __callFunction MessageQueue.js:425:19 __guard$argument_0 MessageQueue.js:112:6 __guard MessageQueue.js:373:10 callFunctionReturnFlushedQueue MessageQueue.js:111:4 callFunctionReturnFlushedQueue [native code]:0 Any suggestions?
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
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.
AppRegistry should be required early in the require sequence to make sure the JS execution environment is setup before other modules are required.
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.
Open the index.js
, the content of the file should be like this:
import { AppRegistry, Platform } from 'react-native'; import App from './App'; AppRegistry.registerComponent('X', () => App); if (Platform.OS === 'web') { const rootTag = document.getElementById('root') || document.getElementById('X'); AppRegistry.runApplication('X', { rootTag }); }
If you have this error Invariant Violation: “main” has not been registered
you have to replace the 'X'
by 'main'
.
Another example :
If you have this error Invariant Violation: “app” has not been registered
you have to replace the 'X'
by 'app'
.
For android :
Open ./android/app/src/main/java/[multiple folders]/MainActivity.java
/** * Returns the name of the main component registered from JavaScript. * This is used to schedule rendering of the component. */ @Override protected String getMainComponentName() { return "X"; }
The 'X'
of MainActivity.java
and index.js
must match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With