Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions: How to debug in WebStorm?

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:

\node_modules\azure-functions-cli\lib\main.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)\JetBrains\WebStorm 2016.2.3\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" --debug-brk=60168 --expose_debug_as=v8debug C:\Users\username\AppData\Roaming\npm\node_modules\azure-functions-cli\lib\main.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?

like image 360
Doug Avatar asked Jan 17 '17 02:01

Doug


People also ask

How do you debug an azure function?

You can easily accomplish this on the Azure Portal: On the Azure Portal, access your Azure Function App, from the left context menu select the option Functions present in the Functions section. On the Functions page, select the Function you want to debug.

How do I run a debug in WebStorm?

Start debugging If your application is running in the development mode on localhost , you can start debugging it from the built-in Terminal ( Alt+F12 ), from the Run tool window, or from the Debug tool window. Just hold Ctrl+Shift and click the URL at which the application is running. Learn more from Debug a Vue.

Does WebStorm have a debugger?

In WebStorm, the JavaScript debugger works out of the box and in most cases its default settings are sufficient. If necessary, you can configure the debugger as described in Configuring JavaScript debugger. WebStorm supports debugging client-side applications running on the built-in or an external web server.


2 Answers

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: ~\AppData\Roaming\npm\node_modules\azure-functions-core-tools\lib\main.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

enter image description here

  1. Edit the file ".vscode\launch.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). enter image description here

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

like image 72
Doug Avatar answered Sep 28 '22 13:09

Doug


  1. Add this to your local.setting.json file under values: "languageWorkers:node:arguments": "--inspect=5858"
  2. Click Edit configuration. Click the plus icon and choose Attachto Node.js/Chrome
  3. Fill in these values for the options: host: localhost - Port: 5858 and set Attac to option to "Crhome or Nod.js>6.3 started with --inpect"
  4. Start the function and run the debugger

See this picture: https://i.stack.imgur.com/hnC74.png

like image 27
Ahmed Elsharif Avatar answered Sep 28 '22 13:09

Ahmed Elsharif