使用 0.0.0.0 主机时 Firebase 模拟器变慢

Firebase Emulator slow when using 0.0.0.0 host

我在使用 Apple Silicon(M1 芯片)的 Mac Mini 上设置 Firebase 模拟器时遇到问题。

我发送到 Firestore 的每个请求(使用模拟器)都需要很长时间才能完成(有时它永远不会完成,我收到一个网络错误,提示无法访问后端):

@firebase/firestore: Firestore (8.2.5): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds. This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

事实证明,这是因为我在 firebase.json 文件中将 host 设置为 0.0.0.0。如果我删除主机字段或将其设置为 localhost,那么我没有任何问题。

这是我的 firebase.json 文件:

{
  "firestore": {
    "rules": "./firestore.rules"
  },
  "emulators": {
    "firestore": {
      "host": "0.0.0.0",
      "port": 8080
    }
  }
}

我将它设置为 0.0.0.0 的原因是因为我需要在不同的机器上(即在平板电脑上)测试我的应用程序,而我们设法让它工作的唯一方法是设置主机为 0.0.0.0,因为该主机将解析与我们的机器关联的所有地址。这样,我就可以使用本地 IP 地址(即 192.168.0.1)访问模拟器。

我注意到这个问题只发生在配备 M1 Apple Silicon 芯片的新 Mac 上。所以,我想知道这是否与 M1 解析 IP 地址的方式有关。

有什么想法吗?

我仍然不确定这是否是 M1 特定的,因为我无法在另一台 M1 机器上测试它,但在 hosts 中的 localhost 旁边添加了我的计算机名称文件似乎已解决此问题:

127.0.0.1    localhost Will.local
::1          localhost Will.local