1

I have changed my index.js to this as im trying to follow this turorial:

https://www.youtube.com/watch?v=6soHPnHxHxI


        import { registerRootComponent } from 'expo';
        import React from "react";
        import { AppRegistry } from "react-native";
        import App from "./App";
        import { name as appName } from "./app.json";
        import { Provider } from "react-redux";
        import { Provider as PaperProvider } from "react-native-paper"
        import store from "./store";
        import 'react-native-gesture-handler';

        const AppRedux = () => {
            <Provider {...{store}}>
                <PaperProvider>
                    <App></App>
                </PaperProvider>
            </Provider>
        }

        // registerRootComponent calls AppRegistry.registerComponent('main', () => App);
        // It also ensures that whether you load the app in the Expo client or in a native build,
        // the environment is set up appropriately
        //AppRegistry.registerComponent(appName, () => AppRedux);


        // registerRootComponent calls AppRegistry.registerComponent('main', () => App);
        // It also ensures that whether you load the app in the Expo client or in a native build,
        // the environment is set up appropriately
        registerRootComponent(AppRedux);

But i keep getting this error:

Invariant Violation: "main" has not been registered. This can happen if: * Metro (the local dev server) is run from the wrong folder.
redoc01
  • 2,107
  • 5
  • 32
  • 64
  • 1
    Did you run `expo start` or `npm start` from the correct folder? – Ragul CS Apr 02 '21 at 16:13
  • @RagulCs, npm start from the correct folder, im using visual source code and running the app from the package.json file, but it is running from the correct folder, which is the root project folder – redoc01 Apr 02 '21 at 16:16
  • 1
    refer this [question](https://stackoverflow.com/questions/62649381/invariant-violation-main-has-not-been-registered) – Ragul CS Apr 02 '21 at 16:18

1 Answers1

1

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'.