如何在WebStorm中调试Firebase云功能? [英] How to debug firebase cloud functions in WebStorm?

查看:78
本文介绍了如何在WebStorm中调试Firebase云功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经启动了一个Firebase云功能项目,想知道如何在WebStorm IDE中运行调试程序?



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



(在我的示例中,我还指定了-port 开关来设置



之后,运行 Run |调试| WebStorm菜单中的调试功能 会加载您的功能并击中您设置的任何断点。


I've started a firebase cloud functions project and want to know how i can get the debugging within the WebStorm IDE running?

I've read that i can archive my goal using @google-cloud/functions-emulator. Therefore I installed it and followed this documentation

After running functions inspect myFunction, I got following output.

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.

I assume debugging should work now. Open myFunction in the browser (e. g. http://localhost:8010/my-project/us-central1/myFunction/) works fine.

Now I'm struggling. What do I have to do to connect the IDE to the debugger or the debugger to the IDE? I have no clue how debugging works.

Expected result: I want to open the function in Chrome Browser following by pausing on the break points in the WebStorm IDE.

Thanks for helping in advance ;)

解决方案

UPDATE 2020:

As of firebase-tools v7.11.0 the Firebase emulator allows debugging of hosted functions with the --inspect-functions flag. This has many advantages over using functions-framework as described below. See this answer for details.

ORIGINAL ANSWER:

Configuring WebStorm to debug a Firebase function can be confusing because there are a couple of different ways to run Firebase functions locally.

Here's what works for me:

  1. npm install --save-dev @google-cloud/functions-framework
  2. In WebStorm create a Node.js debug configuration
    • Run | Edit Configurations... | + | Node.js
  3. Name it as you please (eg, "Debug Function").
  4. In the "JavaScript file:" box, specify: node_modules/@google-cloud/functions-framework/build/src/index.js
  5. In "Application Parameters", specify --target=<your-function-name>
  6. Click OK

It should look something like this:

(In my example, I'm also specifying the --port switch to set the port the function will listen on).

After that, running Run | Debug | Debug Function from the WebStorm menu will load up your function and hit any breakpoints you've set.

这篇关于如何在WebStorm中调试Firebase云功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆