无法使用 exec 连接到 firebase 模拟器套件

Unable to connect to firebase emulator suite with exec

使用以下命令启动 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.

每次 运行 执行命令时都会抛出此错误。有人可以指出可能有什么问题吗?

编辑:来自 firebase 的日志 emulators:start

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 可能适用于您的情况,但我还有其他端口也被模拟器使用。

针对 firepit(可使用 curl 安装的独立 CLI)提交了一个问题:#1868

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

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

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

lsof -ti tcp:8080 | xargs kill

原因:Failed quitting the previous firebase emulator.

lsof command is not availalble on windows powershell.

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

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