Search code examples
reactjsreactjs-native

BundleURL error when trying to generate pre-bundled file


When trying to build ios client in react-native, I modified part of AppDelegate.m file as shown below (i.e., replaced option 1 with option 2):

// OPTION 1
  // Load from development server. Start the server from the repository root:
  //
  // $ npm start
  //
  // To run on device, change `localhost` to the IP address of your computer, and make sure your computer and
  // iOS device are on the same Wi-Fi network.
  //jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];

  // OPTION 2
  // Load from pre-bundled file on disk. To re-generate the static bundle, run
  //
  // $ curl http://localhost:8081/index.ios.bundle -o main.jsbundle
  //
  // and uncomment the next following line
  jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

I downloaded main.jsbundle to the iOS folder where AppDelegate.m is.

$ ls iOS
AppDelegate.h   Base.lproj      Info.plist      main.m
AppDelegate.m   Images.xcassets main.jsbundle

But, if I do the build again in XCode and run it in ios simulator, it pauses in main.m with the following error:

2015-03-31 12:46:28.877 AwesomeProject[26849:1320518] * Assertion failure in -[RCTRootView initWithBundleURL:moduleName:launchOptions:], /Users/yourname/scripts/code/startup/reactnative/AwesomeProject/node_modules/react-native/React/Base/RCTRootView.m:82 2015-03-31 12:46:28.883 AwesomeProject[26849:1320518] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'A bundleURL is required to create an RCTRootView'

So, it seems to be complaining about bundleURL. I will appreciate help with identifying what the issue is.


Solution

  • You need to add the file to the project. To do so, you need to right-click on the project name and select "Add files to MyProject…". Then choose the main.jsbundle.

    Then build your project and it should work.

    See: How to build React Native App for iPhone?