Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unbound breakpoint in vscode for debugging nodejs app in a docker container

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.

like image 511
ShocKwav3_ Avatar asked Jan 29 '26 15:01

ShocKwav3_


1 Answers

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.

like image 109
ryan pickles Avatar answered Feb 01 '26 03:02

ryan pickles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!