"No bundle url present" error with react-native iOS release mode
ios, react-native
Solution
You should do the following:
- Run the following command:`react-native bundle --dev false --platform ios --entry-file index.ios.js --bundle-output ios/main.jsbundle --assets-dest ./ios`
- Add main.jsbundle and assets directory to xcode by dragging them in your project.
Note: You only have to run step 2 the first time.
Problem
I have a native iOS app, and we're using react-native to embed a Facebook-style social feed. To run in debug mode I use the packager server and the following code: ``` NSURL *jsCodeLocation = [NSURL URLWithString:@"http://X.X.X.X:8081/index.ios.bundle?platform=ios"]; bridgeReactView = [[RCTBridge alloc] initWithBundleURL: jsCodeLocation moduleProvider: nil launchOptions:nil]; rootReactView = [[RCTRootView alloc] initWithBridge:bridgeReactView moduleName:@"SocialFeed" initialProperties:@{}]; ``` where X.X.X.X is my local IP address. This works fine, but I can't get it to bundle the react code into the release version. From the official docs and other Stack Overflow posts I've gathered that it was originally necessary to manually bundle the code with something like ``` react-native bundle --entry-file="index.ios.js" --bundle-output="./ios/MyApp/main.jsbundle' --dev=false --platform='ios' --assets-dest="./ios" ``` and change the jsCodeLocation definition above to ``` *jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; ``` Apparently, in more recent versions of react-native, xCode will bundle the code for you automatically if you choose the release build configuration, in which case you must change the above to ``` NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil]; ``` Neither of these methods work for us - in both cases jsCodeLocation gets set to nil, and I get the "No bundle URL present" error: ``` 2017-05-08 15:06:56.738 [fatal][tid:main] No bundle URL present. Make sure you're running a packager server or have included a .jsbundle file in your application bundle. ``` Incidentally, I have tried setting the following values in my Info.plist file: ``` <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSAllowsArbitraryLoadsInWebContent</key> <true/> <key>NSAllowsLocalNetworking</key> <true/> </dict> </key> ```