当我运行一个react-native项目时,我得到一个错误,没有bundle URL,但我不知道我做了什么错误,我很困惑。


当前回答

我也遇到了同样的问题,我通过在AppDelegate中进行更改来解决它。m文件。我改变了

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

to

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];

这对我来说很有效:)

其他回答

当您不允许通过localhost进行不安全连接时,或者您试图通过http接受不安全连接时,就会发生此问题。

要解决这个问题,在info.plist上添加这个:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
        <key>NSAllowsLocalNetworking</key>
        <true/>
    </dict>

这个问题发生在我身上,因为地铁捆绑机启动并收到焦点,而我正在另一个窗口的键盘上打字。我不小心输入了新打开的终端窗口,导致地铁捆扎机崩溃。重新运行react-native run-ios并耐心等待修复了它。

我在我的macbook上通过电缆和wifi连接到网络,关闭wifi,点击运行,它就工作了!

好吧,这听起来可能很奇怪,但这些答案对我都没用。 我现在在react-native 0.60,问题发生在ios和android上。 对我来说唯一有效的解决办法就是跑步 React-native run-ios或React-native run-android 然后,当出现错误时,运行 npm install(保持捆绑器和模拟器打开) 然后运行react-native run-ios或react-native run-android

步骤1: 在xcode中打开。xcodeworkspace项目,通过“Terminal”导航, “开放/ ios /。xcodeworkspace"按Enter键。

步骤2: 删除主机。Jsbundle文件

步骤3: 回到VS Code,输入这个, React-native bundle——entry-file index.js——platform ios——dev false——bundle-output ios/main。Jsbundle——assets-dest ios

这将生成新的主线。jsbundle文件。

步骤4: react-native run-ios

你不会再次看到错误