VS Code中的功能调试 [英] Functions debugging in VS Code

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

问题描述

VS Code 集成终端中,我运行 firebase serve --only功能,托管
然后在调试选项卡中创建了默认的launch.json:

From VS Code integrated terminal I run firebase serve --only functions,hosting then in the debug tab I created the default launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "program": "${file}"
    }
  ]
}

我要调试服务器端(功能/index.js)而不是客户端。

I want to debug the server side (functions/index.js) not the client side.

我已经尝试从 https://code.visualstudio进行一些配置。 com / docs / nodejs / nodejs-debugging ,没有运气。

I've tried some configuration from https://code.visualstudio.com/docs/nodejs/nodejs-debugging with no luck.

如何在VS Code中调试Firebase函数?

推荐答案

更新时间:2019年12月19日

现在可以调试( 放置断点 )firebase函数在VSCode上本地运行。

Update: 19 dec 2019
It's now possible to debug (put breakpoints) firebase functions running locally on VSCode.

1)将firebase-tools更新为至少 v7.11.0 npm i -g firebase-tools

2)将以下内容添加到 launch.json

1) update firebase-tools to atleast v7.11.0 npm i -g firebase-tools
2) add below to launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach",
      "port": 9229,
      "restart": true,
      "skipFiles": ["<node_internals>/**"]
    }
  ]
}

3)运行模拟器: firebase emulators:start --inspect-functions

4)使用<$ c $运行vscode调试器c>附加选项。

3) run the emulator: firebase emulators:start --inspect-functions
4) run the vscode debugger with attach option.

注意:如果要从本地Firebase托管设置测试功能,则需要将托管功能指向本地服务器而不是云服务器。参见此处 https://stackoverflow.com/a/59381328/3073272

note: if you're testing functions from local firebase hosting setup, then you need to point your hosting functions to local server instead of cloud server. see here https://stackoverflow.com/a/59381328/3073272

使用终端调试(无断点)firebase函数的旧答案:

有一个Firebase文档,用于使用Shell 交互式测试功能。您还可以测试https可调用函数。虽然此处未提及附加调试器的步骤。

There's a firebase documentation for Testing functions interactively using shell. You can also test https callable functions. Though steps for attaching a debugger is not mentioned there.

1)打开Goog​​le Cloud Console的服务帐户窗格。

2)确保该App Engine默认服务帐户已选中,然后使用右侧的选项菜单选择创建密钥。

3)出现提示时,选择JSON作为密钥类型,然后单击创建。

4)将您的Google默认凭据设置为指向已下载的密钥

1) Open the Service Accounts pane of the Google Cloud Console.
2) Make sure that App Engine default service account is selected, and use the options menu at right to select Create key.
3) When prompted, select JSON for the key type, and click Create.
4) Set your Google default credentials to point to the downloaded key

$ set GOOGLE_APPLICATION_CREDENTIALS=path\to\key.json

$ firebase functions:shell

Cloud Functions shell可以模拟所有类型带有交互式外壳的功能触发器,用于通过测试数据调用功能。选项因函数类型而异,但是基本用法格式为:

The Cloud Functions shell emulates all types of function triggers with an interactive shell for invoking the functions with test data. Options vary by function type, but the basic usage format is:

myFunctionName(data, options)

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

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