【问题标题】:Error when starting firebase emulator with only funtions option仅使用功能选项启动 Firebase 模拟器时出错
【发布时间】:2020-01-19 16:07:21
【问题描述】:

尝试使用云功能模拟器时,我收到一条消息:

function ignored because the firestore emulator does not exist or is not running

我试过在这里提到:(Firestore/Firebase Emulator Not Running)。

我的函数/package.json 看起来像这样:

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "lint": "eslint .",
    "serve": "firebase serve --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "dependencies": {
    "firebase-admin": "^8.0.0",
    "firebase-functions": "^3.1.0"
  },
  "devDependencies": {
    "eslint": "^5.12.0",
    "eslint-plugin-promise": "^4.0.1",
    "firebase-functions-test": "^0.1.6"
  },
  "private": true
}

我用来启动模拟器的命令:

    firebase emulators:start --only functions

这是我得到的输出:

i  Starting emulators: ["functions"]
!  Your requested "node" version "8" doesn't match your global version "10"
+  functions: Emulator started at http://localhost:5001
i  functions: Watching "C:\Users\MyName\Documents\MyProject\functions" for Cloud Functions...
i  functions[updateFunction]: function ignored because the firestore emulator does not exist or is not running.
+  All emulators started, it is now safe to connect.

我正在函数中执行 console.log,但在端口 (5001) 上看不到它。

任何帮助将不胜感激。

【问题讨论】:

  • 我不明白问题出在哪里。请编辑问题以显示函数的代码、您是如何调用它的,并解释什么没有按您期望的方式工作。
  • 函数本身不相关。我们只是说它正在做一个控制台日志。该函数运行,我在部署时看到控制台日志。当我从使用 firestore 数据库的应用程序写入数据库时​​会触发它。我正在尝试在模拟器中运行该功能。我假设当函数被触发时日志应该出现在模拟器端口(5001)上,但事实并非如此。它确实被触发了,因为我在 firebase 控制台中看到了日志(只是不在模拟器端口上)。我认为这与“由于firestore模拟器而被忽略的功能......”打印有关。这就是问题所在。
  • 接下来,我意识到了一件事。由于我只是启动功能模拟器而不是 firestore 模拟器,因此有问题的打印指的是 firestore 模拟器。所以我启动了所有的模拟器,现在我看不到打印了。那么,现在的问题是,Firestore 的更新是否也需要“模拟”更新而不是真正的更新才能触发“模拟”功能?

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


【解决方案1】:

如果您想触发 Firestore 功能,则需要在本地 Firestore 模拟器中进行更改。本地模拟函数不响应实际的云托管数据库。所有产品上的仿真都必须是本地的。

【讨论】:

  • 谢谢。我正在慢慢到达那里。到目前为止,我实际上一直在写入云托管数据库。我不确定如何为 firestore 数据库本身设置模拟器。我现在知道如何启动模拟器,但在我的应用程序中,我必须写入模拟器而不是实际的云托管数据库。这是我在文档中没有找到的。感谢您迄今为止的帮助。
  • 我的回答是,您不能让本地模拟器响应实际云托管产品中的事件。需要本地 Firestore 模拟器。
  • 我明白了。我只是说我还没有找到一个很好的例子。你能指出一个本地firestore模拟器触发本地firestore功能的例子吗?
  • 1) 您需要运行 firebase init emulators 来设置 Firestore 模拟器。 2) 按照此页面 (firebase.google.com/docs/emulator-suite/…) 上的说明将您的应用程序连接到 Firestore 模拟器。 3) 从您的应用程序到 Firestore 的任何写入都将转到模拟器,并且这些将在适当的时候触发模拟功能。
【解决方案2】:
functions[updateFunction]: function ignored because the firestore emulator does not exist or is not running.

也许“updateFunction”是用于观察 Firestore 文档更改的处理函数,不是吗?

因此您可能需要同时使用函数启动 firestore。

只需使用 firebase.json 配置不带 --only 选项执行

{
  "hosting": {
    "public": "public",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
  },
  "functions": {
    "source": "functions"
  },
  "emulators": {
    "functions": {
      "port": 5001
    },
    "firestore": {
      "port": 8080
    },
    "hosting": {
      "port": 5000
    },
    "ui": {
      "enabled": true,
      "host": "localhost",
      "port": 4000
    }
  }
}

如果你想将你的服务器端函数与你的 IDE 连接起来进行调试,你需要'--inspect-functions' 选项,或者你只需​​要在模拟器日志页面“http://localhost:”中检查日志。 4000/日志”

firebase emulators:start --inspect-functions

【讨论】:

    猜你喜欢
    • 2020-09-09
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-12
    相关资源
    最近更新 更多