Azure Functions:如何在 WebStorm 中调试?

azure-functions-cli 提供了一种启动调试的方法,但这些说明似乎是 Visual Studio 特定的.

我尝试使用与无服务器类似的技巧,方法是在 WebStorm 中设置运行配置以将 JavaScript 文件指向:

ode_modulesazure-functions-clilibmain.js

然后传递应用程序参数:

运行 myFunctionName --debug

这使用 Azure 的工具成功运行了这些功能,但是 WebStorm 都尝试设置调试端口;当 Azure 窗口打开时,它会设置自己的调试端口.

来自网络风暴:

C:Program Files (x86)JetBrainsWebStorm 2016.2.3inunnerw.exe" "C:Program Files odejs ode.exe" --debug-brk=60168 --expose_debug_as=v8debug C:UsersusernameAppDataRoaming pm ode_modulesazure-functions-clilibmain.js 运行 myfunction --debug调试器监听 [::]:60168System.Net.Http.HttpRequestException:发送请求时出错.--->System.Net.WebException:

同样,Azure-cli 说它打开了一个调试端口,但它们不匹配.

因此,调用函数时会忽略设置的断点(尽管它确实运行成功).

有谁知道如何正确配置它才能使用 WebStorm 进行调试?

解决方案

Azure-Functions-CLI 已重命名为 azure-functions-core-tools.如果您仍有 Azure-Functions-CLI,请参阅本文末尾的旧版回复.

如果您正在运行新的 azure-functions-core-tools,它们似乎破坏了运行远程调试器的能力 :-(.

我打开了以下问题,如果他们告诉我,我会更新:https://github.com/Azure/azure-functions-core-tools/issues/378

幸运的是,azure-functions-core 工具的新 Beta 版不具备所有这些 C# 疯狂功能,无法在其他操作系统上运行,并且需要远程调试器.要安装该版本,您可以使用:

npm i -g azure-functions-core-tools@core

安装该版本后,您可以使用良好的ol 标准 Node 运行时"启动内容.

  1. 在 WebStorm 中从 Run -> Edit Configurations 创建一个新的Node.JS".
  2. 为调试命名.
  3. 将 JavaScript 文件设置为:~AppDataRoaming pm ode_modulesazure-functions-core-toolslibmain.js

注意:以上假设您在带有全局标志的 Windows 计算机上安装了 Azure Functions.

  1. 将应用程序参数设置为:start --debug VSCODE

  1. 编辑文件.vscodelaunch.json"并将节点的调试端口更改为9229.
  2. 在 WebStorm 中选择 Run-> Debug:"What_You_Named_the_Remote_Profile"

  3. 添加一些断点.

  4. 导航到您的 API 端点并查看断点是否有效.

注意:默认情况下,函数显示在

注意:以上屏幕截图已根据最新版本的 Azure Functions CLI/进行了更新.早期版本要求您声明应用程序名称,并且不需要 --debug 进行调试.因此,如果您未更新到最新版本的 Azure Functions CLI(现在称为 Azure-Functions-Core-Tools),您可能需要在参数"字段中设置运行 MyApp".

  1. 在 WebStorm 中选择 Run-> Debug:"What_You_Named_the_Remote_Profile"

  2. 添加一些断点.

  3. 导航到您的 API 端点并查看断点是否有效.

注意:默认情况下,函数显示在 http://localhost:7071/api/functionName

The azure-functions-cli offers a way to kickoff debugging, but these instructions seem to be Visual Studio specific.

I tried using a similar trick to serverless by setting up a run config in WebStorm to point the JavaScript file to:

ode_modulesazure-functions-clilibmain.js

And then passing the Application args:

run myFunctionName --debug

This successfully runs the functions with Azure's tools, but both WebStorm tries to set a debugging port; and when the Azure window opens up it sets its own debugging port.

From Webstorm:

C:Program Files (x86)JetBrainsWebStorm 2016.2.3inunnerw.exe" "C:Program Files odejs ode.exe" --debug-brk=60168 --expose_debug_as=v8debug C:UsersusernameAppDataRoaming pm ode_modulesazure-functions-clilibmain.js run myfunction --debug Debugger listening on [::]:60168 System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException:

Likewise, Azure-cli says it opens a debugging port, but they do not match.

As a result, breakpoints set are ignored when the functions are called (Though it does successfully run).

Anybody know how to configure this properly to be able to use WebStorm to debug?

解决方案

Azure-Functions-CLI was renamed to azure-functions-core-tools. If you still have the Azure-Functions-CLI see my legacy response at the end of this post.

If you're running the new azure-functions-core-tools it looks like they broke the capability to run a remote debugger :-(.

I have the following issue opened and I will update if they tell me otherwise: https://github.com/Azure/azure-functions-core-tools/issues/378

Fortunately, the new Beta version of the azure-functions-core tools doesn't have all of this C# craziness that prevents it from running on other OSes and requires a remote debugger. To install that version, you can use:

npm i -g azure-functions-core-tools@core

With that version installed, you can launch things with the good 'ol standard Node runtime.

  1. Within WebStorm from Run -> Edit Configurations create a new "Node.JS".
  2. Give the debugging some type of name.
  3. Set the JavaScript file to: ~AppDataRoaming pm ode_modulesazure-functions-core-toolslibmain.js

NOTE: The above assume you installed Azure Functions on a Windows machine with the global flag.

  1. Set the Application Parameters to: start --debug VSCODE

  1. Edit the file ".vscodelaunch.json" and change the debug port to 9229 for node.
  2. Within WebStorm choose Run-> Debug:"What_You_Named_the_Remote_Profile"

  3. Add some breakpoints.

  4. Navigate to your API end-point and see that the break-points work.

NOTE: By default it appears the function will be at http://localhost:7071/api/functionName

------------------- EDITED But Below Held for Posterity --------------

Okay, it looks like you can not do this with local debugging, but can with "Remote Debugging" within WebStorm.

  1. Within WebStorm from Run -> Edit Configurations create a new "Node.JS Remote Debug".
  2. Give the debugging some type of name.
  3. Hit the + Sign where it says, "Before Launch: External Tool" and choose "Run External Tool".
  4. Hit the + Sign again and fill it out like the screen-shot (This is assuming you installed the Azure Function CLI globally).

NOTE: The above screenshot has been updated based on the latest version of Azure Functions CLI/. Earlier versions required you to state an app name, and did not require --debug to debug. As a result if you are not updated to the latest version of Azure Functions CLI (now known as Azure-Functions-Core-Tools) you may need to have "run MyApp" in the Parameters field.

  1. Within WebStorm choose Run-> Debug:"What_You_Named_the_Remote_Profile"

  2. Add some breakpoints.

  3. Navigate to your API end-point and see that the break-points work.

NOTE: By default it appears the function will be at http://localhost:7071/api/functionName

相关文章