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


当前回答

步骤1: 在xcode中打开。xcodeworkspace项目,通过“Terminal”导航, “开放/ ios /。xcodeworkspace"按Enter键。

步骤2: 删除主机。Jsbundle文件

步骤3: 回到VS Code,输入这个, React-native bundle——entry-file index.js——platform ios——dev false——bundle-output ios/main。Jsbundle——assets-dest ios

这将生成新的主线。jsbundle文件。

步骤4: react-native run-ios

你不会再次看到错误

其他回答

我正在运行iOS模拟器,这个方法有效:

1. 清理本地项目

1.a For Android项目

cd android
gradlew clean

1.b用于iOS项目

cd ios
xcodebuild clean

2. 清理你的反应物贮藏

2.a如果你正在使用npm

  npm start -- --reset-cache

2.b如果你用的是纱线

  yarn cache clean

之后,您可以再次运行您的项目。

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

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

to

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

这对我来说很有效:)

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

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。

Mcafee Macbook用户:

Sudo launchctl remove com.mcafee.agent.macmn

步骤1: 在xcode中打开。xcodeworkspace项目,通过“Terminal”导航, “开放/ ios /。xcodeworkspace"按Enter键。

步骤2: 删除主机。Jsbundle文件

步骤3: 回到VS Code,输入这个, React-native bundle——entry-file index.js——platform ios——dev false——bundle-output ios/main。Jsbundle——assets-dest ios

这将生成新的主线。jsbundle文件。

步骤4: react-native run-ios

你不会再次看到错误