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


当前回答

大多数情况下,此问题发生在DNS查找/ IP查找无法找到本地主机时。

解决方案:

尝试将localhost ip添加到etc主机文件中。

你可以在etc主机文件(/etc/hosts)中添加以下代码行

127.0.0.1 localhost

255.255.255.255 广播主机

::1升。ocalhost

要确认这就是问题所在 你可以在safari上点击bundle url(如果你在chrome中尝试,这将解决,但safari将无法解决它)。http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false

其他回答

只需在终端react-native启动:

cd your react native app directory/ react-native start 

它将启动打包器,现在不要关闭这个终端窗口,在另一个终端窗口运行你的项目。这是我唯一想要的,让它正常工作。

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

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。

关闭全局代理(shadowsocks)

如果您正在运行IOS模拟器,请确保需要运行此命令

react-native运行android 或 npm运行android

一旦你运行以上命令metro bundler将启动,然后运行react- negative run-ios它将工作。

也许你忘了这一步

cd ios && pod install