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


当前回答

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

其他回答

这是react-native v0.42.1的一个问题。尝试关闭所有终端和XCode实例并运行:

launchctl unload ~/Library/LaunchAgents/com.github.facebook.watchman.plist
watchman version
react-native run-ios

只需在终端react-native启动:

cd your react native app directory/ react-native start 

它将启动打包器,现在不要关闭这个终端窗口,在另一个终端窗口运行你的项目。这是我唯一想要的,让它正常工作。

大多数情况下,此问题发生在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

确保你的项目中有.jsbundle

Add

react-native bundle --dev false --entry-file index.js --bundle-output ios/main.jsbundle --platform ios

在react原生代码中 尝试重新打开项目

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