react-native - Metro Bundler 每次都在新窗口中运行

标签 react-native

我将我的 react-native 项目移到了另一台 Mac,现在我无法运行它,也找不到任何解决方案。现在,当我运行 react-native run-ios 时构建成功,但它总是打开新窗口以启动 Metro Bundler。

我已经使用 react-native start 运行 Metro Bundler,并且它保持正常并显示消息:Metro Bundler ready。Loading dependency graph,done。.

但每次我运行 react-native run-ios 它都会打开一个新窗口来启动 Metro Bundler,即使它已经在运行。结果是红屏并显示消息 No bundle URL present.

即使我关闭了我使用 react-native start 运行的 Metro Bundler 并且只执行 react-native run-ios,它运行它自己的 bundler ,也会发生这种情况成功。

知道我为什么会有这种行为吗?

我已经尝试删除 node_modules、npm install、删除 ios/build、再次运行 ios 等。

最佳答案

所以我遇到了这个问题,经过大量挖掘后,我意识到由于某种原因,我的新 Mac 的 /etc/hosts 文件是空的。 iOS 上的 React Native(以及运行 run-iosrun-android 时启动 bundler 的脚本)在 localhost:8081< 查找 bundler ,而不是 127.0.0.1:8081,但由于文件不存在,环回无法正常工作。重点是,我创建了 /etc/hosts/ 并添加了这些行:

127.0.0.1            localhost
::1                  localhost
255.255.255.255      broadcasthost

实际上你只需要第一行,但通常主机文件有这三行所以我把它们都放在那里以防其他任何东西混淆。

关于react-native - Metro Bundler 每次都在新窗口中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51130877/

相关文章:

javascript - 在 React Native 中推送 View Controller 时如何隐藏/删除默认后退按钮?

ios - 在Windows 10上开发React-Native APP时是否可以打开IOS模拟器?

email - 具有电子邮件验证功能的 Firebase 模板

javascript - react native : how to load binary file from remote?

javascript - React-Native TouchableNativeFeedback.Ripple 不起作用

javascript - 解决 React Native 中 'source.uri should not be an empty string' 的问题

javascript - 与 React 的外部链接

javascript - 在 React Native 中如何获取带认证的网络图片?

react-native - 来自 React Native 的 TextInput 不显示输入的文本

android - 在 Android Nexus 5 设备上 react native 开发菜单