VS Code not hitting breakpoints for Node app running in Docker Container
Asked Answered
F

2

7

Summary

I'm running a node app inside a docker container can't get the VS code debugger to hit breakpoints.

Docker Setup

The docker container exposes port 5859. Inside the container the node app is ran with this command:

nodemon -L --watch src --exec babel-node src/server.js -- --inspect=0.0.0.0:5859 --nolazy

It reports that the debugger is listening:

[nodemon] 1.19.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /app/src/**/*
[nodemon] starting `babel-node src/server.js --inspect=0.0.0.0:5859 --nolazy`
Debugger listening on ws://0.0.0.0:5859/5939f6b6-5ade-4ce5-9694-7df5f5b8385b
For help, see: https://nodejs.org/en/docs/inspector

VS Code Setup

And when I fire up the debug profile in VS Code it appears to attach. Below is line from the logs of the running docker container. enter image description here However, no breakpoints are hit when I set them. Is this a babel-node issue? Is there any suggested path forward to get node debugging to work with babel-node?

enter image description here

My VS Code debug config:

  {
        "type": "node",
        "request": "attach",
        "name": "Docker: GraphQL",
        "port": 5859,
        "protocol": "inspector",
        "restart": true,
        "remoteRoot": "/app",
        "localRoot": "${workspaceFolder}"
    }
Fricandeau answered 8/11, 2019 at 22:38 Comment(0)
F
3

I was not able to get this to work with nodemon, but modifying my .babelrc file to include inline source maps triggered VS code to hit the breakpoints I set. My .babelrc file looks like this:

{
    "env": {
        "production": {
            "presets": [
                ["es2015", {"modules": false}],
                "stage-1"
            ]
        },
        "development": {
            "presets": [
                ["es2015"],
                "stage-1"
            ], 
            "sourceMaps": "inline",
            "retainLines": true
        }    }
}

And the corresponding script that docker calls in package.json. Port 5859 is exposed in the docker-compose file.

"start:docker": "babel-node src/server.js --inspect=0.0.0.0:5859 --nolazy",
Fricandeau answered 26/11, 2019 at 14:17 Comment(0)
C
1

For anyone else arriving via a search like me. In my case changing ${workspaceRoot} to ${workspaceFolder} in my vs code launch.json file worked to get a previously working project debuggable again.

Command answered 30/11, 2022 at 12:59 Comment(2)
Under what key?Sharpset
@Sharpset I don't understand your comment sorryCommand

© 2022 - 2024 — McMap. All rights reserved.