Unbound breakpoint in vscode for debugging nodejs app in a docker container
Asked Answered
E

3

14

Minimal reproducible repo: https://github.com/ShocKwav3/babel-node-basic

I am trying to setup debugger with vscode for a nodejs app. I am running the app with babel-node. No matter what I try, the breakpoint shows unbound. I am running the app with this command

nodemon --exec './node_modules/.bin/babel-node --inspect=0.0.0.0 src/bin/www'

Dockerfile:

FROM node:12
WORKDIR /usr/src/app/home_automation_server
COPY package*.json ./
RUN yarn install
COPY . .

Compose config:

server:
    image: home_automation_server
    volumes:
      - .:/usr/src/app/home_automation_server
    working_dir: /usr/src/app/home_automation_server
    ports:
      - 3000:3000
      - 9229:9229
    depends_on:
      - db
      - redis
    networks:
      - servernet
    env_file:
      - ./server.env
      - ./database.env
    command: ["sh", "entrypoint.sh", "run"]
    tty: true

.babelrc:

{
  "presets": [
    [
      "@babel/preset-env",{
        "targets": {
          "node": "current"
        }
      }
    ]
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    ["module-resolver", {
      "root": ["./"],
      "alias": {
        "projectRoot": "./",
        "src": "./src"
      }
    }]
  ],
  "sourceMaps": "inline"
}

launch.json:

{
      "type": "node",
      "request": "attach",
      "name": "Debug: HA dev server",
      "port": 9229,
      "restart": true,
      "trace": true,
      "address": "localhost",
      "localRoot": "${workspaceFolder}/src/bin",
      "remoteRoot": "/usr/src/app/home_automation_server/src/bin",
      "protocol": "inspector",
      "sourceMaps": true
    }

When I connect the debugger it connects If I use inspect-brk the app stops at first line and when debugger connects I can step through. But when I set a breakpoint it does not work and grays out. Says "Unbound breakpoint" What am I doing wrong? I have been at this for a long time and tried almost everything I could find by searching through google.

Endowment answered 7/10, 2020 at 21:21 Comment(3)
Appreciate its not quite the same issue. I had a problem unbound breakpoints in Angular using VSCode. There is some information that may be useful in this github issue. Note, you can collect a debug trace from VSCode following the suggestions in this comment (part of the same github issue)Godiva
Posted the issue in vscode's github, It has a fix now on the nightly build. github.com/microsoft/vscode/issues/108418Endowment
I feel your pain, setting up launch configs in VSCode is a black art, and it takes me hours or even days every time I need to do it. The Node.js website says all you need to do is create a new project and press F5, but this is total bull****Danelaw
C
5

I had a similar problem with unbound breakpoints. My issue was an incorrect field in my launch.json:

"localRoot": "${workspaceFolder}/server",

I had forgot to include the /server. My launch.json file was back one directory relative to the nodejs app I was trying to debug in my directory labelled /server.

Cementum answered 17/2, 2022 at 17:18 Comment(0)
B
0

I had a similar issue, the problem was with launch.json, I had in the property "program": "app.ts", I changed to "program": "$ {file}"**. I could only test the app.ts. In the other files, the breakpoints were set to "unbound" Here is my launch.json

    {

    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Launch Program",
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${file}",
            "sourceMaps": true,
            "preLaunchTask": "tsc: build - tsconfig.json",
            "outFiles": [
                "${workspaceFolder}/dist/**/*.js"
            ]
        }
    ]
}
Birkenhead answered 9/5, 2021 at 0:45 Comment(1)
Thanks for posting your launch config. When I tested this, I got different behaviors depending on how I set my default profile for the terminal window. Which profile are you using?Danelaw
N
0

I have a few project.json files in my quite large project. I added "sourceMap": true to the "build":{ "options":{}} section of the portion that I needed to debug. That worked.

Nosh answered 4/6, 2024 at 19:28 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.