node.js - 如何在WebStorm中调试firebase云功能?

标签 node.js firebase debugging google-cloud-functions webstorm

我已经启动了一个 Firebase 云函数项目,并想知道如何在 WebStorm IDE 中运行调试?

我了解到我可以使用 @google-cloud/functions-emulator 存档我的目标。 因此我安装了它并遵循此 documentation

运行functionsspect myFunction后,我得到以下输出。

Warning: You're using Node.js v10.6.0 but the Google Cloud Functions runtime is only available in Node.js 6 and Node.js 8. Therefore, results from running emulated functions may not match production behavior.
Debugger for app listening on port 9229.

我认为调试现在应该可以工作了。在浏览器中打开 myFunction (例如 http://localhost:8010/my-project/us-central1/myFunction/ )工作正常。

现在我正在挣扎。要将 IDE 连接到调试器或将调试器连接到 IDE,我需要做什么?我不知道调试是如何工作的。

预期结果:我想在 Chrome 浏览器中打开该函数,然后在 WebStorm IDE 中的断点处暂停。

感谢您提前提供帮助;)

最佳答案

截至firebase-tools v7.11.0 ,Firebase 模拟器现在支持使用 --inspect-functions 选项附加调试器。这允许您使用 WebStorm 调试本地运行的 Firebase 函数,同时使用其余的(已大大改进的)模拟器工具。

首先确保您拥有必要的 firebase-tools:

$ npm install firebase-tools@latest

现在您可以从项目目录启动 Firebase 模拟器中的函数:

$ firebase emulators:start --inspect-functions

输出将显示如下内容:

$ firebase emulators:start --inspect-functions
i  emulators: Starting emulators: functions, hosting
⚠  functions: You are running the functions emulator in debug mode (port=9229). This means that functions will execute in sequence rather than in parallel.
✔  functions: Using node@10 from host.

请注意上面输出中的“port=9229”。这是我们要告诉 WebStorm 附加的端口。

在 WebStorm 中打开您的项目,然后:

  1. 选择运行|编辑配置...
  2. 在“运行/调试配置”窗口中,点击“+”按钮并选择“附加到 Nodejs/chrome”选项。

Attach

  • 选择新配置,并将其配置为连接到上面输出中显示的端口(在我的例子中为 9229):
  • enter image description here

  • 点击应用确定。您的配置已保存。
  • 从 WebStorm 主菜单中,您现在可以选择运行 |调试...并选择您的新配置。 WebStorm 将附加到托管您的函数的进程,您可以使用调试功能(断点等),就像 WebStorm 中的正常调试 session 一样。

    关于node.js - 如何在WebStorm中调试firebase云功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54424869/

    相关文章:

    node.js - npm install bower 使用 -g 与 --save-dev

    Android Kotlin DSL - Unresolved reference : firebaseAppDistribution

    firebase - 对于 firebase 应用程序分发,发行说明的最大大小是多少?

    c# - 应用程序在 Debug模式下运行速度非常慢

    javascript - 如何在 Node Js 中上传期间更改目录并重命名文件?

    android - 我在用户注册时发送推送通知,它只向注册用户发送通知,我可以将其更改为每个使用该应用程序的人吗?

    Node.js 回调 |具有 waterfall 流的异步 forEach 嵌套循环

    firebase - 使用时间戳查询 Firebase 数据

    ios - 应用程序因 EXC_BAD_INSTRUCTION (SIGILL) 崩溃?

    javascript - 调试 Firefox 扩展 - 如何查看 XPI 中包含的所有 JS 和 XUL 文件?