Search code examples
azurevisual-studio-codevscode-debuggerlernamonorepo

vscode launching function app in lerna monorepo


First, I have a monorepo that is structured like so:

repo-name/
    packages/
        backend/
        frontend/
    .vscode/

The backend is an Azure function app structured like so:

backend/
    functions/
        funcOne/
        funcTwo/
    scripts/
        start-debug.sh
    package.json

Second, for the backend's package.json, I have a script:

  "debug": "npm run build && FUNCTION_APP_PORT=7071 ./scripts/start-debug.sh",

The start-debug.sh script looks like this:

#!/bin/bash 
set -e
cd ./functions 
func extensions install 
func host start -p $FUNCTION_APP_PORT --debug VSCode

I'm trying to write a launch configuration so that I can debug my functions in VSCode.

I have tried a number of variations based on what I have found out there, but nothing seems to work. Does anyone have any suggestions?

Here's my latest attempt:

{
    "name": "Launch Backend Functions",
    "type": "node",
    "request": "launch",
    "address": "localhost",
    "protocol": "inspector",
    "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/lerna",
    "runtimeArgs": [
        "exec",
        "--scope",
        "actual-name-of-backend-package",
        "--",
        "npm"
    ],
    "args": ["run", "debug"],
    "port": 1234
}

Solution

  • OK, here's the launch configuration in VSCode that worked for me:

    {
      "type": "node",
      "request": "attach",
      "name": "Attach by Process ID",
      "protocol": "legacy",
      "processId": "${command:PickProcess}",
      "port": 9229
    },
    

    My steps are

    1) Go to my backend repo, and run npm run debug which runs my start-debug.sh script.

    2) In VS Code, I attach to a nodejsWorker out of azure-function-core-tools.

    Now, I can step through my functions.