如何 运行 具有特定主机地址的 firebase 模拟器?

How to run the firebase emulator with a specific host address?

我正在尝试将物理设备上的 flutter 应用程序 运行 与本地计算机上的 firebase 模拟器连接起来,按照 SOF 中的这些步骤进行操作,但是当 运行 这个命令

firebase emulators:start --inspect-functions --export-on-exit ./test_data/ --import ./test_data/

firebase.json 中使用此配置:

{
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "storage": {
    "rules": "storage.rules"
  },
  "emulators": {
    "auth": {
      "host": "0.0.0.0",
      "port": 9099
    },
    "functions": {
      "host": "0.0.0.0",
      "port": 5001
    },
    "firestore": {
      "host": "0.0.0.0",
      "port": 8080
    },
    "storage": {
      "host": "0.0.0.0",
      "port": 9199
    },
    "ui": {
      "enabled": true
    }
  }
}

它会产生以下输出:

i  emulators: Starting emulators: auth, functions, firestore, storage
⚠  functions: You are running the functions emulator in debug mode (port=9229). This means that functions will execute in sequence rather than in parallel.
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: database, hosting, pubsub
✔  functions: Using node@14 from local cache.
i  emulators: Shutting down emulators.
i  functions: Stopping Functions Emulator
i  hub: Stopping emulator hub
⚠  firestore: Port 8080 is not open on 0.0.0.0, could not start Firestore Emulator.
⚠  firestore: To select a different host/port, specify that host/port in a firebase.json config file:
      {
        // ...
        "emulators": {
          "firestore": {
            "host": "HOST",
            "port": "PORT"
          }
        }
      }
i  emulators: Shutting down emulators.

和这个错误:

Error: Could not start Firestore Emulator, port taken.

显而易见的解决方案

杀死任何使用端口 8080 的应用程序,更有可能是上一个会话的 firestore 模拟器,从此 。杀掉应用后,再次运行命令,出现同样的错误。

备注

即使在本地网络中使用我的机器地址而不是 0.0.0.0 也不起作用,结果相同。

我建议从 firestore.json 中删除:"host": "0.0.0.0",Firebase Documentation

此命令帮助我终止了端口 8080 上的应用 运行:

lsof -ti tcp:8080 | xargs kill

我不得不使用另一个端口,比如 8000,而不是 8080 作为 firebase.json 中的 firestor 条目,所以命令可以 运行.

firebase emulators:start --inspect-functions --export-on-exit ./test_data/ --import ./test_data/

取自此github issue。此外,使用 0.0.0.0 将使 firebase 模拟器使用 localhost 或本地网络中机器的 ip 地址。
虽然 lsof -i :8080 没有 return 任何结果表明有一个应用程序使用端口 8080