react-native: Cannot find entry file index.ios.js [index.android.js] in any of the roots

[edit #2: this is now fixed as of 0.45.1 and 0.46.0-rc.2 - @hramos]

[edit: scroll down for additional details - @hramos]

Description

Recently upgrade to RN 0.45 from 0.42 (I was hit with #14225 and I figured I might as well spend the time migrating)

Error in Bundler:

error: bundling: Error
    at DependencyGraph._getAbsolutePath (/Users/mytotoro/Desktop/app/node_modules/react-native/packager/src/node-haste/DependencyGraph.js:280:11)
    at DependencyGraph.getDependencies (/Users/mytotoro/Desktop/app/node_modules/react-native/packager/src/node-haste/DependencyGraph.js:218:26)
    at Resolver.getDependencies (/Users/mytotoro/Desktop/app/node_modules/react-native/packager/src/Resolver/index.js:107:27)
    at /Users/mytotoro/Desktop/app/node_modules/react-native/packager/src/Bundler/index.js:591:37
    at Generator.next (<anonymous>)
    at step (/Users/mytotoro/Desktop/app/node_modules/react-native/packager/src/Bundler/index.js:12:445)
    at /Users/mytotoro/Desktop/app/node_modules/react-native/packager/src/Bundler/index.js:12:605
    at process._tickCallback (internal/process/next_tick.js:109:7)
Bundling `index.android.js`  0.0% (0/1), failed.

and red screen showing

Response error 404, Cannot find entry file index.android.js in any of the roots: [\"/Users/mytotoro/desktop/app/node_modules/react-native/packager\"]

With NotFoundError

Looking for JS files in
   /Users/mytotoro/Desktop/app/node_modules/react-native/packager 


React packager ready.

Reproduction Steps and Sample Code

"react": "^16.0.0-alpha.12",
"react-native": "^0.45.0-rc.2",

Mac: 10.12.4
node: v7.10.0
npm: 4.6.1

I run react-native run-android from the root directory of my project as I have always been doing:

total 456
-rw-r--r--    1 mytotoro  staff     175 Apr  7 23:36 index.ios.js
-rw-r--r--    1 mytotoro  staff     175 Apr  7 23:36 index.android.js
drwxr-xr-x    7 mytotoro  staff     238 Apr  7 23:36 Tests
-rw-r--r--    1 mytotoro  staff    2113 Apr  7 23:36 README.md
drwxr-xr-x    6 mytotoro  staff     204 Apr  7 23:37 ignite
drwxr-xr-x   15 mytotoro  staff     510 Apr  7 23:38 App
-rw-r--r--    1 mytotoro  staff  216323 Apr  7 23:39 yarn.lock
drwxr-xr-x   15 mytotoro  staff     510 May 29 13:42 android
-rw-r--r--    1 mytotoro  staff    3888 May 29 14:18 package.json

This issue comes up for iOS as well (I run on device through xcode) but the offending file is index.ios.js

[edit: adding duplicates -@hramos]

Duplicates

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 37
  • Comments: 76 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Run the packager first with npm start -- --reset-cache from your project’s root directory, then run react-native run-android.

Got this error after upgrading to React Native v0.49.0. It seems that in v0.49.0 the app entry is now a single index.js file instead of the two index.ios.js and index.android.js. At the time of writing v0.49 release notes haven’t been published but starting a new project:

react-native init AwesomeProject --version 0.49.0

revealed a single index.js file. Seems to work for me so far.

From the release notes, under Breaking Changes:

screen shot 2017-10-16 at 9 31 03 am

I have the same problem on android & windows 10 in last 2 days. Also tried with npm start -- --reset-cache and a lot of other commands (from comments) but does’t help.

In my case the problem was with watchman (on windows 10), as the @jeanlauliac mentioned. I removed it and it works good now. It’s little bit tricky, cause the first you need to do is open terminal, run couple times watchman watch-del-all, then watchman shutdown-server, then Ctrl+Alt+Del, and remove watchman.exe from processes. Then delete your C:\Users\yourusername\AppData\Local\Watchman directory, and remove it from PATH environment variables on windows.

I hope this will help someone.

npm: 4.6.1 node: v8.1.4 react-native-cli: 2.0.1 react-native: 0.44.2

@IgorVanian, In 49 the entry must be index.js instead of having two different files (index.android.js & index.ios.js). It should have been listed as a breaking change.

Thanks @nicovak for the link explaining it.

Same here, steps to reproduce and temp fix:

$ react-native init testapp
# testapp created

$ cd testapp

$ react-native -v
react-native-cli: 2.0.1
react-native: 0.45.0

$ react-native run-ios
# On simulator, I'm getting:
# Cannot find entry file index.ios.js in any of the root ["../testapp/node_modules/react-native/packager"]

Temporary fix:

  1. Close terminal launched by running react-native run-ios
  2. Run the following:
$ npm start -- --reset-cache
Loading dependency graph, done.
  1. On simulator, type cmd + r Simulator will load the project properly.

Note: I have to do the temporary fix every single time.

I had the same problem after upgrading from 46.x to 49.x even after creating a new index.js and change the

AppDelegate.m jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

and MainApplication.java

@Override
   protected String getJSMainModuleName() {
     return "index";
   }

Solution was Uninstall the app from the emulator Clean the build Build the app again (react-native run-android) After that the app was installed on the emulator and did work again.

@willdawsonme this does fix it, is there a way to make the fix more permanent (Normally, when I ran react-native run-android, a new terminal window would pop up)

New terminal, doesn’t work:

Looking for JS files in
   /Users/mytotoro/Desktop/app/node_modules/react-native/packager 

Now when I run npm start -- -reset-cache first - runs in place of current terminal

Looking for JS files in
   /Users/mytotoro/Desktop/app

I’m consolidating various related issues into this one. As far as I can tell, #14314, #14366, #14376, and #14386 are all duplicates.

Description

React Native projects built with native code targeting 0.45 are encountering an issue during app launch, where the app is unable to connect to the packager. The user is presented with a RedBox error with the following text:

Cannot find entry file index.ios.js in any of the roots: ["/path_to_app/node_modules/react-native/packager"]

User reports claim the same issue affects Android, which may result in an error like so (included here for discoverability/search):

Cannot find entry file index.android.js in any of the roots: ["/path_to_app/node_modules/react-native/packager"]

The packager displays the following error when the RedBox is displayed:

./node_modules/react-native/packager ~
 ┌────────────────────────────────────────────────────────────────────────────┐ 
 │  Running packager on port 8081.                                            │ 
 │                                                                            │ 
 │  Keep this packager running while developing on any JS projects. Feel      │ 
 │  free to close this tab and run your own packager instance if you          │ 
 │  prefer.                                                                   │ 
 │                                                                            │ 
 │  https://github.com/facebook/react-native                                  │ 
 │                                                                            │ 
 └────────────────────────────────────────────────────────────────────────────┘ 
Looking for JS files in
   /path_to_app/node_modules/react-native/packager 


React packager ready.

Loading dependency graph, done.
error: bundling: Error
    at DependencyGraph._getAbsolutePath (/path_to_app/node_modules/react-native/packager/src/node-haste/DependencyGraph.js:280:11)
    at DependencyGraph.getDependencies (/path_to_app/node_modules/react-native/packager/src/node-haste/DependencyGraph.js:218:26)
    at Resolver.getDependencies (/path_to_app/node_modules/react-native/packager/src/Resolver/index.js:107:27)
    at /path_to_app/node_modules/react-native/packager/src/Bundler/index.js:591:37
    at Generator.next (<anonymous>)
    at step (/path_to_app/node_modules/react-native/packager/src/Bundler/index.js:12:445)
    at /path_to_app/node_modules/react-native/packager/src/Bundler/index.js:12:605
    at process._tickCallback (internal/process/next_tick.js:103:7)
Bundling `index.ios.js`  0.0% (0/1), failed.

Reproduction Steps and Sample Code

This can be reproduced on a clean, new project. First, create a new project using the CLI, then start the packager and launch the app:

react-native init MyApp
cd MyApp
react-native run-ios

At this point, the iOS Simulator will launch and display a RedBox with the error Cannot find entry file index.ios.js in any of the roots: ["/redacted/MyApp/node_modules/react-native/packager"], where redacted is the actual path to the parent folder of the project.

Solution

The user may work around this issue by killing the packager that is launched by react-native run-ios, and starting an independent packager using npm start. At this point, the user may tap Reload JS or hit Cmd+R to connect the iOS Simulator to the new packager instance, resolving the RedBox error.

Additional Information

  • React Native version: 0.45
  • Platform: iOS (user reports claim this affects Android as well, but was not verified by yours truly)
  • Development Operating System: macOS Sierra
  • Dev tools:
    • react-native-cli: 2.0.1

This is now fixed as of 0.45.1, thanks to @skevy.

Run npm install react-native to install the latest version which is now 0.45.1, or run npm install react-native@0.45.1 if you want to be explicit.

If you were targeting the RC, you can install 0.46.0-rc.2: npm install react-native@0.46.0-rc.2.

It’s still looking for index.*.js files even after 0.49.1 update. Any tweaks I need to apply?

I have the same problem here. Currently affecting me when starting on a new project. @ekryski is right, this issue is not present in v0.44 Hence, my current workaround is to init the new React Native project, using React Native v0.44

  1. Install rninit (https://www.npmjs.com/package/rninit) npm i -g rninit
  2. Init project with react-nativev0.44.0 (https://www.npmjs.com/package/rninit#usage) rninit init [Project Name] --source react-native@0.44.0

I guess I’ll upgrade react native version in my project when this is fixed upstream.

Edit: Ok, I feel dumb now. react-native-cli already does this. Forget what I wrote above. react-native init [Project Name] --version 0.44.0

#14412 should fix this in master. We’ll need to cut a new 0.45 release.

npm start -- --reset-cache does not help at all react-native-cli: 2.0.1 react-native: 0.45.1

This issue is still in version 0.52.2. Any permanent solution? It is very sad that someone can run blank RN project.

Same here … upgraded to 0.45 and facing this issue of having to do --reset-cache everytime before doing react-native run-ios or android . Anyone found a permanent fix ?

Still an issue with

react-native -v react-native-cli: 2.0.1 react-native: 0.54.2

Any help is welcome

I’ve also started getting:

Bundler returns `NotFoundError: Cannot find entry file index.js in any of the roots:

after upgrading to react-native@0.55.1.

To fix this, I had to remove my index.ios.js and index.android.js files and create a single index.js file in the root of my project. Looks like this default behavior changed in react-native, but I didn’t see anything mentioning this in the release notes.

Hope this helps someone else looking for the fix.

@jeanlauliac Disabling it is not an option because I get EMFILE, too many open files error since my project is somehow big for Windows (seriously, roughly 3k files including node_modules and Windows can’t handle it…)

installed react-native-cli and this command worked for me react-native bundle --platform ios --dev false --entry-file index.js --bundle-output ios/main.jsbundle

Did npm install --save react-native@0.45.1 and even react-native upgrade

Still the same error…

EDIT: Happens on Windows only though (OSX ❤️)

I encounter the exact same issue now with 0.45.0-rc.2 in a fresh react-native init project.

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.

// android/app/src/main/java/<yourPackage>/MainApplication.java

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
  //...
  @Override
  protected String getJSMainModuleName() {
    return "index";
  }
};
// ios/<project>/AppDelegate.m

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

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

My react native is at version 0.49.5 and I’m still having this issue. None of the above temporary solutions worked for me either.

EDIT: My issue was due to another module I was using to throw another error.

watchman really killed me 😦 Thank you hmatijevic for your post!

Still the same on 0.46.0-rc.0 (released a few hours ago)

Hi everyone! Maybe I can help you If you have the same problem you can search: -https://stackoverflow.com/questions/38701115/windows-android-react-native-server-crashes-very-often/43217182#43217182 ERROR: KyANon\RNFBSDK.…\node_modules\react-native-fbsdk\android\build\generated\source\buildConfig\release\com\facebook\reactnat ive\androidsdk’ => cd android -> gradlew clean -> cd… -> react-native start (npm start)

And about we can “Cannot find entry file index.ios.js [index.android.js] in any of the roots”:

https://user-images.githubusercontent.com/15075926/34285093-8ba05c2a-e709-11e7-89df-8310ba98c81e.PNG

Create file “index.android.js” by copy "index.j"s and rename to “index.android.js”

Because as Mr. Hramos talked: “From the release notes, under Breaking Changes:” https://user-images.githubusercontent.com/165856/31623607-cc69304a-b254-11e7-8fd3-cb81c897ca41.png We miss two files index.android.js and index.ios.js so we can copy to create that files.(In this case I just copy and rename not refactor name. you can delete indext.js)

So goodbye and good luck for you!

@hmatijevic you saved my life. I’ve been struggling against it for days/weeks.

Also worth noting this should be fixed in 45.

You’re totally right, I deleted watchman from global packages and now it’s working!

@IgorVanian , @kabala, do you use watchman? Since it happens only on Windows it might be related to https://github.com/facebook/metro-bundler/issues/2. If you don’t use watchman, then it could be another issue with how we handle paths. Does the problem go away temporarily when using --reset-cache?