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


当前回答

大多数情况下,此问题发生在DNS查找/ IP查找无法找到本地主机时。

解决方案:

尝试将localhost ip添加到etc主机文件中。

你可以在etc主机文件(/etc/hosts)中添加以下代码行

127.0.0.1 localhost

255.255.255.255 广播主机

::1升。ocalhost

要确认这就是问题所在 你可以在safari上点击bundle url(如果你在chrome中尝试,这将解决,但safari将无法解决它)。http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false

其他回答

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

如果您正在运行IOS模拟器,请确保需要运行此命令

react-native运行android 或 npm运行android

一旦你运行以上命令metro bundler将启动,然后运行react- negative run-ios它将工作。

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

npm install

react-native run-ios

对我来说,问题是它不能创建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原生构建。

检查你的网络代理,最好关闭它。

或者你应该找其他方法来维护打包服务器