Node.js 使用firebase模拟器运行JS文件时出现问题:exec

Node.js 使用firebase模拟器运行JS文件时出现问题:exec,node.js,firebase,google-cloud-firestore,firebase-tools,Node.js,Firebase,Google Cloud Firestore,Firebase Tools,我正在试用新的Firebase模拟器UI。在中,我注意到有一个CLI命令允许我们运行脚本文件: firebase模拟器:执行脚本路径 启动的模拟器后,在scriptpath处运行脚本 Firebase.json中配置的Firebase产品。模拟器进程将 脚本完成运行后自动停止 虽然文档中没有提到它应该是什么类型的脚本文件,但我认为它可能是测试脚本或可用的JavaScript文件,可以独立使用node filename.js执行,不会出现任何错误。这是有意义的,因为我实际上可以运行一个初始JS文件

我正在试用新的Firebase模拟器UI。在中,我注意到有一个CLI命令允许我们运行脚本文件:

firebase模拟器:执行脚本路径

启动的模拟器后,在scriptpath处运行脚本 Firebase.json中配置的Firebase产品。模拟器进程将 脚本完成运行后自动停止

虽然文档中没有提到它应该是什么类型的脚本文件,但我认为它可能是测试脚本或可用的JavaScript文件,可以独立使用node filename.js执行,不会出现任何错误。这是有意义的,因为我实际上可以运行一个初始JS文件,该文件将一些测试数据预先填充到Firestore Emulator中,以便进行进一步的测试

但由于我以前启动过模拟器,我必须打开一个新的命令窗口实例来运行firebase模拟器:exec命令。不幸的是,我遇到了以下错误:

D:\Firebase\my-project>firebase emulators:exec setup-db.js
i  emulators: Starting emulators: functions, firestore, database, hosting, pubsub
!  hub: emulator hub unable to start on port 4400, starting on 4401 instead.
!  emulators: It seems that you are running multiple instances of the emulator suite for project my-project-id. This may result in unexpected behavior.
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub
!  functions: Port 5001 is not open on localhost, could not start Functions Emulator.
!  functions: To select a different host/port, specify that host/port in a firebase.json config file:
      {
        // ...
        "emulators": {
          "functions": {
            "host": "HOST",
            "port": "PORT"
          }
        }
      }
i  emulators: Shutting down emulators.

Error: Could not start Functions Emulator, port taken.
注意这一行:

!!模拟器:您似乎正在为project my-project-id运行模拟器套件的多个实例。这可能会导致意外行为

那么,我如何运行firebase仿真器:在仿真器按照firebase文档中提到的那样启动后执行,我可以为此运行JS文件吗?提前谢谢

更新:

如果我只运行firebase模拟器:exec setup-imtp-db.js,而没有事先运行firebase模拟器:start命令,则会遇到以下错误:

D:\Firebase\my-project>firebase emulators:exec setup-db.js
i  emulators: Starting emulators: functions, firestore, database, hosting, pubsub
!  hub: emulator hub unable to start on port 4400, starting on 4401 instead.
!  emulators: It seems that you are running multiple instances of the emulator suite for project my-project-id. This may result in unexpected behavior.
i  emulators: Shutting down emulators.
i  hub: Stopping emulator hub
!  functions: Port 5001 is not open on localhost, could not start Functions Emulator.
!  functions: To select a different host/port, specify that host/port in a firebase.json config file:
      {
        // ...
        "emulators": {
          "functions": {
            "host": "HOST",
            "port": "PORT"
          }
        }
      }
i  emulators: Shutting down emulators.

Error: Could not start Functions Emulator, port taken.
请注意,setup-imtp-db.js不包含任何云函数代码,只包含一个独立的js文件,该文件通过Admin SDK将另一个JSON文件中的数据填充到Firestore中。我正在使用Node.js 12.14.0和firebase tools 8.4.0。

根据:

模拟器:exec启动本地Firebase模拟器,运行测试 脚本,然后关闭模拟器

因此,scriptpath参数实际上并不是要运行一个JavaScript文件,该文件预先填充Firestore Emulator上的数据,并显示在其Emulator UI上,用于UI功能测试或集成测试。emulators:exec将在完成测试脚本的执行后立即关闭模拟器


正如@Doug Stevenson在评论中所建议的,如果需要模拟器进行正确的错误处理,或者需要一个新功能,那么可以在上发布请求或错误报告

如果Firebase CLI没有按照您期望的方式工作,我建议在其GitHub上发布一个问题。我以前去过那里,但我不了解他们的贡献指南,所以不妨在这里发布。如果没有人可以回答,我可以使用其他替代方案,以避免我们的功能和集成测试在谷歌云上花费太多。