【问题标题】:Unable to connect to firebase emulator suite with exec无法使用 exec 连接到 Firebase 模拟器套件
【发布时间】:2020-07-14 16:41:25
【问题描述】:

使用以下命令启动 firebase 项目模拟器(使用云功能和 firestore)

firebase emulators:start

它运行成功,并为我提供了连接函数的路径,并显示了 firestore 的本地主机 url。

然后,为了执行我的笑话测试,运行以下命令

firebase emulators:exec --only firestore jest

根据文档,要连接到本地 firstore,我们需要使用 exec。但它抛出错误。

i  emulators: Starting emulators: firestore
⚠  emulators: emulator hub unable to start on port 4400, starting on 4401
✔  hub: emulator hub started at http://localhost:4401
i  Shutting down emulators.
i  Stoppping emulator hub
⚠  Port 8080 is not open on localhost, could not start firestore emulator.
i  To select a different host/port for the emulator, update your "firebase.json":
    {
      // ...
      "emulators": {
        "firestore": {
          "host": "HOST",
          "port": "PORT"
        }
      }
    }
i  Shutting down emulators.
Error: Could not start firestore emulator, port taken.

每次运行 exec 命令时都会引发此错误。有人能指出可能是什么问题吗?

编辑:来自 firebase 模拟器的日志:开始

firebase emulators:start
i  emulators: Starting emulators: functions, firestore, hosting, pubsub
✔  hub: emulator hub started at http://localhost:4400
⚠  Your requested "node" version "8" doesn't match your global version "10"
✔  functions: functions emulator started at http://localhost:5001
i  firestore: Serving ALL traffic (including WebChannel) on http://localhost:8080
⚠  firestore: Support for WebChannel on a separate port (8081) is DEPRECATED and will go away soon. Please use port above instead.
i  firestore: firestore emulator logging to firestore-debug.log
✔  firestore: firestore emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i  hosting[website]: Serving hosting files from: public
✔  hosting[website]: Local server: http://localhost:5000
i  hosting[admin]: Serving hosting files from: public
✔  hosting[admin]: Local server: http://localhost:5005
i  hosting[b2b]: Serving hosting files from: public
✔  hosting[b2b]: Local server: http://localhost:5006
i  hosting[b2c]: Serving hosting files from: public
✔  hosting[b2c]: Local server: http://localhost:5007
i  hosting[sdk]: Serving hosting files from: public
✔  hosting[sdk]: Local server: http://localhost:5008
✔  hosting: hosting emulator started at http://localhost:5000
i  pubsub: pubsub emulator logging to pubsub-debug.log
✔  pubsub: pubsub emulator started at http://localhost:8085

更新

重新开始时,也会显示提到的错误。但是关闭端口使其工作。

在 package.json 的 scipts 部分下面添加

"kill": "npx kill-port 5000 5001 8080 8085 4000 9229"

然后运行

npm run kill

上面列出的所有端口都不是必需的。仅 8080 可能适用于您的情况,但我还有其他端口也被模拟器使用。

【问题讨论】:

  • 听起来你正在运行另一个模拟器进程。
  • 我尝试重启 VS 代码。但还是一样的情况。让我杀死端口看看。
  • @DougStevenson 还是一样的情况:|
  • npx kill-port 8080 为我解决了这个错误:Port 8080 is not open on localhost, could not start firestore emulator

标签: firebase google-cloud-firestore firebase-cli


【解决方案1】:

我关闭了终端,然后再次打开,再次启动命令,它就可以工作了

【讨论】:

    【解决方案2】:

    lsof 命令在 windows powershell 上不可用。

    更好的跨平台解决方案是:npx kill-port 8080

    【讨论】:

      【解决方案3】:

      在您的终端中输入此内容,其中 8080 是您的端口号:

      lsof -ti tcp:8080 | xargs kill
      

      原因:Failed quitting the previous firebase emulator.

      【讨论】:

      • 'lsof' is not recognized as an internal or external command, operable program or batch file. 有什么建议吗?
      【解决方案4】:

      firepit 存在一个问题(可通过 curl 安装的独立 CLI):#1868

      将其安装为 Node 包可能会有所帮助:npm install -g firebase-tools

      如果情况已经如此,您可能应该在那里提出问题。

      【讨论】:

      • ✔ firestore:firestore 模拟器开始于localhost:8080 -> 这意味着它的可访问权限?
      • 我尝试更改为 9081,但仍然抛出相同的错误。
      • 之前的实例好像没有正常关闭;因为日志还抱怨其他端口;例如。 ⚠ emulators: emulator hub unable to start on port 4400, starting on 4401netstat -lntu 会显示正在发生的事情(至少在 Linux 上); Windows 应该有类似的命令。
      • lsof -t -i tcp:4400 | xargs 杀死 -9 | firebase emulators:exec --only firestore jest -> 我尝试终止开放端口并运行 exec,它所做的是,它终止了以 firebase emulators:start 启动的进程
      • 作为一种解决方法,这可能就足够了;仍然是为什么它不能正确终止实例以使其按预期工作的问题。重启VS代码是没有意义的,因为这不会影响占用端口的服务器。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 2021-04-29
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      相关资源
      最近更新 更多