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


当前回答

我发现绕过这个最简单/最快的方法是在模拟器中退出应用程序(2 x Cmd + Shift + H)并重新启动。

其他回答

我尝试了下面所有的解决方案,但都不起作用:

Sudo xcodebuild -license或 使用rm -r build删除build文件夹并运行react-native run-ios或 NPM启动并运行react-native run-ios 添加NSAppTransportSecurity到localhost

我是这样解决的:

打开主机文件sudo vi /private/etc/hosts(如果你使用VSCode,使用这个sudo code /private/etc/hosts) 如果不存在,添加三行

127.0.0.1 localhost
255.255.255.255 localhost
::1 localhost

再次运行react-native Run -ios。

...发生这种情况的另一个原因是,如果你已经安装了Visual Studio Code React Native Tools,但你一直试图在终端中使用React Native:它第一次会工作,但随后它会停止并显示红色的no bundle屏幕。

从vscode启动react native工作得很好…

这是react-native v0.42.1的一个问题。尝试关闭所有终端和XCode实例并运行:

launchctl unload ~/Library/LaunchAgents/com.github.facebook.watchman.plist
watchman version
react-native run-ios

当您不允许通过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它适合我