A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.[ios, xcode]

Viewed 36215

I have android and ios app in react native which both uses webview to show webpage as application. Since I had to change package name to deploy it on google play since first one package name was occupied. I changed app.json file and all names in android folder and that's ok.

Now my question is what I need to change in my ios folder in order to my app work in xcode. I have this error.

Invariant Violation: "RestApp" 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.registerComponent wasn't called.

This is my app.json file

{
  "name": "restapphhopp",
  "displayName": "RestApphhopp"
}

Index.js file

/**
 * @format
 */

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);
6 Answers

The issue here is with the name you are using for your app

Invariant Violation: "RestApp" 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.registerComponent wasn't called.

your index file is using the appName from app.json name field to register your component, which in your case is "name": "restapphhopp"

change your moduleName in ios AppDelegate.m file to restapphhopp

moduleName:@"restapphhopp"

Name in the app.json should be the same as the name in package.json

recheck your name is same in app.json and in strings.jsx file

if using expo

  1. delete node_modules and your lockfile (package-lock.json / yarn.lock)
  2. run yarn or npm install
  3. run expo install react-native-safe-area-context

I also needed to edit this line in AppDelegate.mm

UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"YOURAPPNAME", nil);

After updating this, in addition to all other steps, I then ran

npm start --reset-cache

Open new terminal:

cd ios
pod install
npm run ios

Hope this helps someone!

  1. First, you will need to start Metro, the JavaScript bundler that ships with React Native. Metro "takes in an entry file and various options, and returns a single JavaScript file that includes all your code and its dependencies."
npx react-native start
  1. Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following:
npx react-native run-android
Related