Fix Error: unable to resolve module './index.android' from ' '

It's throwing error because it's not able to find index.android file in your root directory of project , if you have index.ios in your project

You can you create index.android.js file and in that import original index.js file and check if it works (quick fix)

So Basically After React v0.49, you don't need index.ios.js and index.android.js. You only need the index.js:

But There are two cases when this issue arise

  • If you are updating from an old project you need to make sure the correct files are loaded from native code to adopt the new single file entry point.
  • And second is inconsistent behaviour of react native as some people randomly getting this issue in newer version because of watchman or cache

Solution for first case

//For android in this directory you need to make this change android/app/src/main/java/<yourPackage>/MainApplication.java

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
  //...
  @Override
  protected String getJSMainModuleName() {
    return "index";
  }
};

//and for ios in this directory ios//AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  NSURL *jsCodeLocation;

  jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  //...
}

These two solution also works in some cases

  • watchman watch-del-all && rm -rf package-lock.json && rm -rf node_modules && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-map-*

or

  • remove index.ios.js and index.android.js files and create a single index.js

There are certain scenarios so it's hard to determine why anyone is getting this issue.