Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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}"
    }
like image 588
colinwurtz Avatar asked Nov 08 '19 22:11

colinwurtz


1 Answers

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",
like image 68
colinwurtz Avatar answered Oct 03 '22 01:10

colinwurtz