Stan Wiechers
Stan Wiechers

Reputation: 2092

Breakpoint set but not yet bound in Visual Studio Code for a dockerized node process

I am trying to use the debugger in Visual Studio Code on a macOS Catalina for a node app. I created a very simple example to illustrate my case.

index.js

require('http').createServer( (request, response) => {
  response.writeHead(200, {'Content-Type': 'text/plain'})
  response.end('Hello World\n');
  response.end();
}).listen(3000);

Dockerfile

FROM node:12.14.0-alpine 
COPY . /src
CMD ["node","--inspect=0.0.0.0", "src/index.js"]

I build the Dockerfile

docker build . -t debugtest

and then run it

 docker run -p 3000:3000 -p 9229:9229 debugtest

I can access http://localhost:3000/.

I set a breakpoint in index.js.

enter image description here Then setup a debugger target in visual studio code

{
  "version": "0.2.0",
  "configurations": [
  {
    "type": "node",
    "request": "attach",
    "name": "Attach",
    "port": 9229,
    "skipFiles": [
      "<node_internals>/**"
    ]
  }
  ]
}

Now when I start the debugger in visual code the red dot of the breakpoint disappears and "Breakpoint set but not yet bound" appears.

enter image description here

I have seen that question in various spots but none of the solutions worked. When I run the node process outside of docker node --inspect index.js it works without a hitch.

I am using version 1.41.1 of visual studio code and docker 2.1.0.5.

Upvotes: 4

Views: 1595

Answers (1)

Stan Wiechers
Stan Wiechers

Reputation: 2092

Turns out I was omitting the remoteRoot attribute in launch.json. The below works.

launch.json

{
  "version": "0.2.0",
  "configurations": [
  {
    "type": "node",
    "request": "attach",
    "name": "Attach",        
    "port": 9229,
    "remoteRoot": "/src/",
    "skipFiles": [
      "<node_internals>/**"
    ]
  }
  ]
}

Upvotes: 8

Related Questions