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


当前回答

当您不允许通过localhost进行不安全连接时,或者您试图通过http接受不安全连接时,就会发生此问题。

要解决这个问题,在info.plist上添加这个:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
        <key>NSAllowsLocalNetworking</key>
        <true/>
    </dict>

其他回答

关闭全局代理(shadowsocks)

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

我也遇到了这个问题(第一次开始使用React Native)。当一个ios模拟(react-native run-ios)正在运行时,问题消失了。我运行npm install,然后再次运行react-native run-ios。在终端窗口中,它显示正在捆绑,然后模拟器显示欢迎屏幕。

在react-native init PropertyFinder行之后检查这个链接,尝试使用npm start(这对我来说是有效的)

========================================================================

16.9更新

我的端口8081被McAfee阻塞。直接使用不同的端口不能工作react-native start——port=8082和react-native run-ios——port=8082

几乎所有的解都试过了。但是什么都不管用。

        "react": "16.9.0",
        "react-dom": "^16.12.0",
        "react-native": "0.61.5",

解决方案:

在Xcode中搜索8081,并将它们全部替换为8082。然后运行相同的命令来构建和运行应用程序。应用程序运行顺畅

react-native start --port=8082
react-native run-ios --port=8082

对于我的用例,我必须删除node_modules目录并运行npm install。

$ rm -rf node_modules   (make sure you're in the ios project directory)
$ npm install

如果你得到错误“dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.58。Dylib”,执行以下操作:

$ brew uninstall --force node --ignore-dependencies node
$ brew uninstall icu4c --ignore-dependencies icu4c
$ brew install icu4c
$ brew unlink icu4c && brew link icu4c --force
$ brew install node

$ npm install

另一件对我有用的事情是,在xcode中打开项目,然后清理并构建它。通常它会重新运行打包服务器并解决问题。