question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to modify existing RN project to use single index.js entry point (both iOS and Android)

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment: OS: macOS High Sierra 10.13 Node: 8.6.0 Yarn: 1.2.0 npm: 5.5.1 Watchman: 4.9.0 Xcode: Xcode 9.0.1 Build version 9A1004 Android Studio: 2.3 AI-162.4069837

Packages: (wanted => installed) react: 16.0.0-beta.5 => 16.0.0-beta.5 react-native: 0.49.3 => 0.49.3

Steps to Reproduce

(Write your steps here:)

  1. Have an existing React Native 0.48 project
  2. Upgrade to React Native 0.49.3
  3. Rename index.android.js to index.js, and delete index.ios.js
  4. Use jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.bundle?platform=ios&dev=true"]; in AppDelegate.m

Expected Behavior

My expectation was that RN 0.49.* would know to use index.js as the entry point, but the packager and output suggested that it was still trying to use the old entry points (i.e. index.android.js).

Actual Behavior

The packager showed this output, suggesting that it was using old entry points:

Bundling `index.android.js`  [development, non-minified]  0.0% (0/1), failed.
error: bundling failed: Error
    at DependencyGraph._getAbsolutePath (/Users/sunw/Skale/Repos/skale-react-native/Skale/node_modules/metro-bundler/src/node-haste/DependencyGraph.js:305:11)
    at DependencyGraph.getDependencies (/Users/sunw/Skale/Repos/skale-react-native/Skale/node_modules/metro-bundler/src/node-haste/DependencyGraph.js:283:4236)
    at Resolver.getDependencies (/Users/sunw/Skale/Repos/skale-react-native/Skale/node_modules/metro-bundler/src/Resolver/index.js:129:5)
    at /Users/sunw/Skale/Repos/skale-react-native/Skale/node_modules/metro-bundler/src/Bundler/index.js:642:39
    at Generator.next (<anonymous>)
    at step (/Users/sunw/Skale/Repos/skale-react-native/Skale/node_modules/metro-bundler/src/Bundler/index.js:13:1336)
    at /Users/sunw/Skale/Repos/skale-react-native/Skale/node_modules/metro-bundler/src/Bundler/index.js:13:1496
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

Screenshots (Android and iOS, respectively):

screenshot_1508818289

img_0358

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
achuvmcommented, Oct 27, 2017

I’m pretty sure this could’ve been done prior to the defaulting to only 1 index.js file

For Android, go to your Module: app’s build.gradle and add the following above the line: apply from: "../../node_modules/react-native/react.gradle"

project.ext.react = [
    entryFile: "index.js"
]

In MainApplication.java, you need to override another function in the anonymous ReactNativeHost class by adding this:

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

For iOS, go to your AppDelegate.m and change "index.ios" to "index" in this line:

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

Depending on how old your project is, you might have a Build Phases Script that looks like this:

export NODE_BINARY=node

../node_modules/react-native/scripts/react-native-xcode.sh ../index.ios.js

In that case, you can remove the argument ../index.ios.js or simply rename it to index.js

These changes were tested with a new RN 47.2 project that I upgraded to RN 49.3 with a single index.js file. These instructions were also used to upgrade a RN 47.2 project w/ our Viro platform to a RN 49.3 project with a single index.js file too.

Hope that helps!

edit1: left out another android fix edit2: added possibly additional iOS changes

4reactions
sunweiyangcommented, Oct 25, 2017

Unfortunately @duailibe, the issue persists even after deleting ios/build/ and android/app/build/.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customizing the project structure | React Made Native Easy
Create a file index.js at app/index.js . This file will serve as the common entry point for both Android and iOS projects. Modify...
Read more >
Ask Question - Stack Overflow
js as the entry point. this is the full error: Loading dependency graph, done. Error: Unable to resolve module ./index.android from ``:.
Read more >
Integration with Existing Apps - React Native
React Native is great when you are starting a new mobile app from scratch. ... a single view or user flow to existing...
Read more >
Using module bundlers with Firebase - Google
JavaScript module bundlers can do many things, but one of their most useful features is the ability to add and use external libraries...
Read more >
Integrating React Native with existing Android and iOS native ...
export NODE_BINARY=node ../node_modules/react-native/scripts/react-native-xcode.sh · react-native bundle --platform android --dev false --entry-file index.js -- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found