【问题标题】:How to run the firebase emulator with a specific host address?如何使用特定主机地址运行 firebase 模拟器?
【发布时间】:2021-09-12 15:15:53
【问题描述】:

我正在尝试将我在物理设备上运行的颤振应用程序与本地计算机上的 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.

这个错误:

错误:无法启动 Firestore 模拟器,端口已占用。

明显的解决方案

SOF 终止使用端口 8080 的任何应用程序,更有可能是之前会话的 Firestore 模拟器。杀死应用程序并再次运行命令后,出现同样的错误。

注意

即使在本地网络中使用我的机器地址而不是 0.0.0.0 也不起作用并导致相同的输出。

【问题讨论】:

    标签: flutter firebase-tools


    【解决方案1】:

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

    这个命令帮助我杀死了在端口 8080 上运行的应用程序:

    lsof -ti tcp:8080 | xargs kill

    【讨论】:

    • 我确实杀死了正在使用该端口的应用程序,但错误仍然存​​在。此外,删除"host": "0.0.0.0" 会将其默认为 localhost 我相信这意味着它在物理设备上运行应用程序时将不起作用。
    【解决方案2】:

    我必须使用另一个端口,例如 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 模拟器使用本地主机或本地网络中机器的IP 地址。
    虽然lsof -i :8080 没有返回任何结果表明有应用程序使用端口8080

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-02
      • 2021-03-21
      • 2011-07-01
      • 2021-07-27
      • 1970-01-01
      • 2021-03-11
      • 2021-02-06
      • 1970-01-01
      相关资源
      最近更新 更多