【问题标题】:Running the firebase emulators when the functions directory is in a different project/location当函数目录位于不同的项目/位置时运行 firebase 模拟器
【发布时间】:2021-05-02 20:34:57
【问题描述】:

我在 Windows 10 机器上本地运行所有 Firebase 模拟器。 但是,我正在单独运行我的函数模拟器,因为函数目录位于不同的项目/位置。 看来触发器没有被模拟,我收到下面的警告。除了触发器/背景功能之外的所有东西似乎都可以正常工作。

有什么解决办法吗?

i  emulators: Starting emulators: functions
!  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 myproject-dev. This may result in unexpected behavior.
!  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, hosting, pubsub
!  Your requested "node" version "10" doesn't match your global version "12"
!  logging: Logging Emulator unable to start on port 4500, starting on 4501 instead.
!  ui: Emulator UI unable to start on port 4000, starting on 4003 instead.
i  ui: Emulator UI logging to ui-debug.log
i  functions: Watching "R:\myproject\myprojectCloud\functions" for Cloud Functions...
!  functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
i  functions[memberUpdate]: function ignored because the firestore emulator does not exist or is not running.

更新: 我的文件夹结构。

  1. R:/customer/customer-cloud-project/functions
  2. R:/customer/customer-web-app/

我可以运行位置 2 中的所有模拟器,除了函数模拟器,因为没有函数目录。 因此,我在函数文件夹的位置 1 中运行以下命令: firebase 模拟器:启动 --only 函数

这很好用,因为它运行了 2 个模拟器实例。但是,触发器/后台功能不会运行,因为它找不到在不同端口上运行的 firestore 模拟器。

【问题讨论】:

  • “函数目录位于不同的项目/位置”是什么意思?您是否有多个项目,一个具有 Firestore,另一个具有功能?您从哪个目录运行每个模拟器?您提供的信息越多,我们就越容易理解问题。现在我无法重现你的设置。
  • 我有 2 个项目。一个用于我的云功能,另一个用于我的前端应用程序,我还使用规则、索引等初始化了 firestore。模拟器似乎需要与 firestore 项目在同一项目中的“functions”目录才能一起运行它们。这说明清楚了吗?
  • 向问题添加了更多信息
  • 是的,据我了解,“functions”目录必须与firestore项目位于同一项目中。
  • @marian.vladoi 我找到了解决方案。在下面添加。

标签: google-cloud-firestore google-cloud-functions firebase-tools


【解决方案1】:

解决方案是使用符号链接。 这基本上是函数项目中另一个目录的快捷方式。

如果其他人想要这样做,Windows 上的命令是: mklink /D "R:\firestore-project\functions" "R:\cloud-functions-proj\functions"

您需要以管理员身份运行命令提示符。

请在此处查看我的问题以获取更多详细信息: https://github.com/firebase/firebase-tools/issues/3092#issuecomment-771159457

注意: 创建符号链接时可以指定绝对路径或相对路径。 相对是最好的选择,否则它不太可能在其他人的环境中工作。在要创建链接的目录中运行它:

mklink /D "models" "..\..\..\myapp\src\app\models"

【讨论】:

  • 对于使用 Mac OS 的任何人,您都可以这样做 ln -s ../../path/to/functions functions 注意:点和路径只是一个示例。更改为您的相对(或绝对)路径。
  • 另外,请记住更新您的 firestore-project 的 firebase.json 中的“源”字段以指向符号链接文件夹。
猜你喜欢
  • 1970-01-01
  • 2021-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-18
  • 2019-09-25
相关资源
最近更新 更多