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


当前回答

我也有同样的错误,只能通过Xcode运行应用程序。React-native run-ios不起作用。要解决这个问题,你需要删除YOUR_PROJECT/ios/build/的build文件夹。在此之后,您应该能够再次通过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 v0.42.1的一个问题。尝试关闭所有终端和XCode实例并运行:

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

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

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。

在重新启动我的mac后,我也遇到过这种情况。当你在模拟器上运行应用程序时,会打开一个launchPackager终端窗口。我关闭了该窗口并终止了进程(我也关闭了模拟器),然后再次运行react-native run-ios,一切正常。

首先关闭模拟器,然后在终端上运行这些程序

npm install

react-native run-ios