尝试生成预捆绑文件时出现BundleURL错误

时间:2015-03-31 16:50:38

标签: reactjs reactjs-native

尝试在react-native中构建ios客户端时,我修改了AppDelegate.m文件的一部分,如下所示(即,用选项2替换选项1):

// 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"];

我已将main.jsbundle下载到iOS所在的AppDelegate.m文件夹。

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

但是,如果我在XCode中再次进行构建并在ios simulator中运行它,它会在main.m暂停,并出现以下错误:

  

2015-03-31 12:46:28.877 AwesomeProject [26849:1320518] *断言   失败 - [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] * 终止   应用程序由于未捕获的异常'NSInternalInconsistencyException',   原因:'创建RCTRootView'

需要一个bundleURL

所以,它似乎在抱怨bundleURL。我将非常感谢帮助确定问题所在。

1 个答案:

答案 0 :(得分:6)

您需要将文件添加到项目中。 为此,您需要右键单击项目名称,然后选择“将文件添加到MyProject ...”。然后选择 main.jsbundle

然后构建你的项目,它应该工作。

请参阅:How to build React Native App for iPhone?