首页 > 解决方案 > 当函数目录位于不同的项目/位置时运行 firebase 模拟器

问题描述

我在 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:/客户/客户云项目/功能
  2. R:/客户/客户网络应用程序/

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

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

标签: google-cloud-firestoregoogle-cloud-functionsfirebase-tools

解决方案


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

如果其他人想这样做,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"

推荐阅读