【问题标题】:React Native - ios - loading from pre-budled file failsReact Native - ios - 从预打包文件加载失败
【发布时间】:2015-12-09 19:13:05
【问题描述】:

我有一个可以与开发服务器完美配合的 react 本机应用程序。

我想从 xcode 项目中捆绑要在本地提供的应用程序。所以,我启动了开发服务器并运行了

curl 'http://localhost:8080/index.ios.bundle?platform=ios&dev=true' -o ios/main.jsbundle

这在我的 ios 文件夹中创建了一个名为 main.jsbundle 的新文件。然后我去了我的AppDelegate.m 并将我的jsCodeLocation 更改为

jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 

一切似乎都正确,但是当我从 xcode 构建项目时,我在模拟器顶部看到 Loading from bundled file ... 而没有其他任何内容。

从我看到的 chrome 调试器

    Uncaught NetworkError: Failed to execute 'importScripts' on 
'WorkerGlobalScope': The script at 
'file:///Users/benconant/Library/Developer/CoreSimulator/Devices/3054F999-82…281E-90D6-410D-BC17-
81A6D1DFCA2A/Eastern%20Car%20Service.app/main.jsbundle' failed to 
load.messageHandlers.executeApplicationScript @ 
debuggerWorker.js:18onmessage @ debuggerWorker.js:42

如果我单击文件路径,它会将我带到包含我的应用程序的所有 javascript 代码的捆绑包。不知道为什么这个包无法加载......它似乎与从服务器发送的包相同

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8080/index.ios.bundle?platform=ios&dev=true"];

仅供参考...我还尝试按照在https://facebook.github.io/react-native/docs/running-on-device-ios.html#content 找到的创建捆绑包的官方步骤进行操作,这导致了同样的错误。我的想法是,如果捆绑包是从我的开发服务器加载的,我应该确保我放入项目中的那个与那个相同。

【问题讨论】:

    标签: ios objective-c xcode facebook react-native


    【解决方案1】:

    好的……经过几个小时的挖掘和玩耍,我解决了这个问题。首先我需要禁用 chrome 调试功能 command + option + z 这就是导致

    Uncaught NetworkError: Failed to execute 'importScripts' on 
    'WorkerGlobalScope': The script at 
    'file:///Users/benconant/Library/Developer/CoreSimulator/Devices/3054F999-82…281E-90D6-410D-BC17-
    81A6D1DFCA2A/Eastern%20Car%20Service.app/main.jsbundle' failed to 
    load.messageHandlers.executeApplicationScript @ 
    debuggerWorker.js:18onmessage @ debuggerWorker.js:42  
    

    然后我得到了这篇文章中描述的错误"Invariant Violation: Application AwesomeProject has not been registered" When building for iOS device with static jsbundle ... 我最终在 AppDelegate.m 和我的根组件中将我的应用程序从 App 重命名为更合适的名称。繁荣......它奏效了。我认为最大的收获是确保在尝试从包加载时禁用 chrome 调试器。

    【讨论】:

    • 我遇到了同样的问题,只是我想运行调试器进行一些调试。您知道如何在“从捆绑文件加载”停留在页面顶部(并且应用程序的其余部分未加载)的情况下运行调试器吗?
    • 与@Brad 相同的问题。有什么解决办法吗?
    猜你喜欢
    • 2017-09-09
    • 1970-01-01
    • 2016-10-27
    • 2019-06-06
    • 2019-08-16
    • 1970-01-01
    • 2019-03-22
    • 2021-12-16
    • 2021-02-04
    相关资源
    最近更新 更多