Unable to modify existing RN project to use single index.js entry point (both iOS and Android)
See original GitHub issueIs 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:)
- Have an existing React Native 0.48 project
- Upgrade to React Native 0.49.3
- Rename index.android.js to index.js, and delete index.ios.js
- 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):
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m pretty sure this could’ve been done prior to the defaulting to only 1
index.js
fileFor Android, go to your
Module: app
’sbuild.gradle
and add the following above the line:apply from: "../../node_modules/react-native/react.gradle"
In
MainApplication.java
, you need to override another function in the anonymous ReactNativeHost class by adding this:For iOS, go to your
AppDelegate.m
and change"index.ios"
to"index"
in this line:Depending on how old your project is, you might have a Build Phases Script that looks like this:
In that case, you can remove the argument
../index.ios.js
or simply rename it toindex.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 singleindex.js
file too.Hope that helps!
edit1: left out another android fix edit2: added possibly additional iOS changes
Unfortunately @duailibe, the issue persists even after deleting
ios/build/
andandroid/app/build/
.