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


当前回答

解决错误No bundle URL present by:

在你的项目根目录中运行以下命令删除iOS构建目录,并在重新构建之前杀死其他React Native会话(假设它们运行在默认端口8081上):

Rm -rf ios/build/;Kill $(lsof -t:8081);react-native run-ios

更新你的React Native工作流,通过将上述命令组合成一个别名,并将其附加到你的Bash配置文件.bashrc,以避免这些错误发生:

Echo "alias rni=\"kill \$(lsof -t -i:8081);Rm -rf ios/build/;React-native run-ios\"" >> ~/.bashrc;源~ / . bashrc

现在你可以用一个简单的别名快捷方式运行React Native iOS构建(不用担心出现一些常见的红色死亡错误屏幕):

rni

其他回答

假设你正在使用nvm并且安装了多个版本的node,下面是解决方案:

假设你在节点v6.9.5中运行npm install -g react-native-cli。 现在运行nvm alias default 6.9.5将节点v6.9.5设为默认值 现在运行react-native run-ios

问题是,你通过nvm安装了多个版本的node,为了安装react-native-cli,你已经切换或安装了最新版本的node,它还没有被标记为nvm中的默认节点。当你运行react-native run-ios时,会打开另一个新的终端窗口,其中默认的nvm不会指向你安装react-native-cli的节点版本。只要遵循上面的设置,我希望能有所帮助。

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

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

to

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

这对我来说很有效:)

关闭全局代理(shadowsocks)

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

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。

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