【发布时间】:2020-09-10 08:25:56
【问题描述】:
我正在试用新的 Firebase 模拟器 UI announced on May 21, 2020。在Firebase Docs 中,我注意到有一个 CLI 命令允许我们运行 脚本文件:
firebase emulators:exec scriptpath在
scriptpath处运行脚本在启动模拟器后 在 firebase.json 中配置的 Firebase 产品。模拟器进程将 脚本运行完毕后自动停止。
虽然文档没有提到它应该是什么类型的脚本文件,但我认为它可能是一个 测试脚本 或一个可以独立执行的 JavaScript 文件 node filename.js 没有任何错误。这是有道理的,因为我实际上可以运行一个初始 JS 文件,该文件将一些测试数据预填充到 Firestore 模拟器 以进行进一步测试。
但是由于我之前已经启动了模拟器,所以我必须打开一个新的命令窗口实例来运行firebase emulators: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.
注意这一行:
! emulators: It seems that you are running multiple instances of the emulator suite for project my-project-id. This may result in unexpected behavior.
那么,我如何运行 firebase emulators:exec 模拟器启动后 如 Firebase 文档中所述,我可以运行 JS 文件来达到上述目的吗?提前致谢!
更新:
如果我只运行firebase emulators:exec setup-imtp-db.js 而没有事先运行firebase emulators:start 命令,我会遇到以下错误:
请注意,setup-imtp-db.js 不包含任何 Cloud Functions 代码,而只是一个独立的 JS 文件,该文件通过 Admin SDK 将数据从另一个 JSON 文件填充到 Firestore。我正在使用Node.js 12.14.0 和firebase-tools 8.4.0。
【问题讨论】:
-
如果 Firebase CLI 未按您预期的方式工作,我建议在其 GitHub 上发布问题。 github.com/firebase/firebase-tools
-
我以前去过那里,但我不明白他们的贡献指南,所以不妨在这里发布。没人能回答也没关系,我可以使用其他替代方案,只是为了避免我们的功能和集成测试在 Google Cloud 上花费过多。
标签: node.js firebase google-cloud-firestore firebase-tools