1 min read

Daily Dispatch 27 - Debugging Issues

Daily Dispatch 27 - Debugging Issues

So hello, it’s been a while, and I haven’t being keeping up with my daily dispatches, or maybe my days are longer than yours. Relativity man, who knows?

So I was playing around with a Node.js (nodejs.org) project hosting it using Docker alongside a Postgres database.

And I was all happy and dandy until I wanted to debug an error on VSCode.

And I couldn’t.

So I went far and wide, talked with many friends (I wish), and came across this cool article Debugging uncompiled Typescript code running on a Docker container | by Mitsuhide Ohi | Medium.

This article pointed me towards the right direction, but I had to add a few things.

1 – First of all, I didn’t need to add a debug script to my package.json. I merely replaced my --inspect flag with itself + server_address:port --inspect=0.0.0.0:9229.
2 – I did add the next line on my tsconfig.json.

"sourceMap": true

3 — Here’s where things differ a lot from the article, my vscode launch.json configuration didn’t use the sourceMapPathOverrides (it did nothing for me).

Instead I replaced it with these two cool properties ( remoteRoot and localRoot):

{
    "name": "Docker Node.js Launch",
    "type": "node",
    "request": "attach",
    "port": 9229,
    "address": "localhost",
    "skipFiles": [
        "<node_internals>/**"
    ],
    "remoteRoot": "/usr/app",
    "localRoot": "${workspaceFolder}",
}

4 – Now to the docker-compose.yml file, I added to my mainApp service the docker port for debugging

ports:
 - 3000:3000 # my previous port
 - 9229:9229 # docker debugger port

5 – After all that, I had to run docker-compose up -d --build --force-recreate since I changed the docker-compose.yml file.

And then BOOM! It worked.