【问题标题】:BundleURL error when trying to generate pre-bundled file尝试生成预捆绑文件时出现 BundleURL 错误
【发布时间】:2015-03-31 16:50:38
【问题描述】:

尝试在react-native 中构建ios 客户端时,我修改了AppDelegate.m 文件的一部分,如下所示(即,将选项1 替换为选项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"];

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

$ 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。对于确定问题所在的帮助,我将不胜感激。

【问题讨论】:

    标签: reactjs reactjs-native


    【解决方案1】:

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

    然后构建您的项目,它应该可以工作。

    见:How to build React Native App for iPhone?

    【讨论】:

    • 谢谢!我错过了什么真是令人头疼。
    猜你喜欢
    • 2021-05-25
    • 2020-12-03
    • 2020-05-16
    • 2013-03-29
    • 1970-01-01
    • 2021-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多