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


当前回答

我们通过删除构建脚本中的SKIP_BUNDLING选项来解决这个问题,RN文档建议添加该选项来加快调试构建。真正的修复(为了我们的原因)包含在RN 0.57中:

https://github.com/facebook/react-native/issues/20553

其他回答

关闭/打开设备/ mac上的wi-fi,重建应用程序

更深层次的调试:查看XCode日志,它可能包含:“无法连接到服务器”和确切的URL。

请确保.plist文件中的ATS设置是正确的。

你可以在/ios/{{project_name}}/Info.plist找到这个文件

Localhost必须定义为异常请求目标,如下所示:

<key>NSAppTransportSecurity</key>
    <dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

*(不要忘记在发布版本中删除此选项..)

试着加上这句话:

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

对于我的用例,我必须删除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

对我来说,问题是它不能创建JS包。当从Xcode构建时,它没有声明错误,所以你无法知道这一点。要查找错误,请运行以下命令。

React-native bundle——platform ios——dev false——entry-file index.ios.js——bundle-output ./ios/release/mainJsbundle——assets-dest ./ios/release/main.jsbundle

对我来说,错误是缺少PureRenderMixin组件。解决方案可以在这里找到:https://github.com/facebook/react-native/issues/13078。基本上你必须手动安装react@16.0.0-alpha.3。这可以通过运行这个命令来完成。

NPM I——保存react@16.0.0-alpha.3

现在每个人都遇到了这个问题,因为新版本的react alpha正在发布(特别是alpha.5),它们破坏了react原生构建。