【问题标题】:How to attach debugger with firebase:shell - firestore clould functions如何使用 firebase:shell 附加调试器 - firestore 云功能
【发布时间】:2019-02-26 17:15:45
【问题描述】:

已在本地成功配置 Firestore 云功能。

能够使用以下命令在本地运行函数。

  1. firebase 函数:shell --port=3535

firebase var data = require('./data'); wChangedEvent(data.default);

... ... 在 wChangedEvent 中打印任何 console.log。 所以这工作正常。

但我需要在 Visual Studio 代码中附加调试器。我尝试了以下配置。

   {
        "type": "node",
        "request": "attach",
        "name": "Attach",
        "port": 3535,
        "protocol": "inspector"
    },

但它不起作用。

【问题讨论】:

  • --port 标志不适用于节点调试器,它是别的东西。我能告诉你的最好的是,你可以使用 vscode 来查找用于模拟你的函数的进程,并且每个函数都有自己的进程。很难区分它们。
  • 如何在visual studio代码中附加到进程?
  • 附加到 Visual Studio 代码中的进程未达到断点
  • 也许还不支持?我看到This Issue 没有解决。

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


【解决方案1】:

您可以使用函数模拟器。文档很少,但这是一个好的开始:https://firebase.google.com/docs/functions/config-env

$ npm install -g @google-cloud/functions-emulator`

$ functions start

$ functions deploy api --trigger-http --timeout 600s

$ functions inspect api --port 9229

创建一个 VS Launce 配置:

{
  "type": "node",
  "request": "attach",
  "name": "Attach",
  "port": 9229 
}

现在你可以F5开始调试了。

这将不会自动从您的数据库接收触发器,但它仍然非常有用,因为您可以使用 http 请求来触发函数并对其进行调试。

提示:将此脚本添加到您的package.json,以便您可以轻松地npm run debug 构建并部署到模拟器:

"scripts": {
  ...
  "debug": "npm run build && functions deploy api --trigger-http --timeout 600s && functions inspect api --port 9229"` 
}

【讨论】:

    【解决方案2】:

    截至 2020 年底,this pull request 增加了对 --inspect-functions 标志的支持。

    firebase functions:shell --inspect-functions
    

    除非您明确提供另一个,否则它将打开默认节点调试器端口9229

    使用 Jetbrains IDE,您可以使用 "Attach to Node.js/Chrome" run configuration 附加到正在运行的进程。

    【讨论】:

    • 在 Visual Studio 中,添加一个 .vscode/launch.json 包含以下内容:{ "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "Attach Firebase Functions", "port": 9229, "restart": true, "skipFiles": ["<node_internals>/**"] } ] }
    • --inspect-functions 也可以使用模拟器获得:firebase emulators:start --inspect-functions
    猜你喜欢
    • 2018-06-23
    • 2021-04-14
    • 2020-10-30
    • 2018-05-09
    • 2019-11-12
    • 1970-01-01
    • 2022-12-20
    • 2020-08-02
    • 2019-08-07
    相关资源
    最近更新 更多