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


当前回答

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

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。

其他回答

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

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。

在我的情况下,我不小心从Xcode的构建阶段删除了这个脚本。

所以,一定要有这个脚本。如果没有,只需点击“+”&选择“新建运行脚本阶段”,然后粘贴以下代码。

export NODE_BINARY=node
../node_modules/react-native/scripts/react-native-xcode.sh

确保你的项目中有.jsbundle

Add

react-native bundle --dev false --entry-file index.js --bundle-output ios/main.jsbundle --platform ios

在react原生代码中 尝试重新打开项目

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

npm install

react-native run-ios

在我的情况下,终端抛出绝对没有错误,问题是我的mac的vpn连接,所以我不得不断开vpn,问题得到了解决。