Nodejs remote debug with docker and compose do not pause on breakpoints

Hello!

My configuration works on localhost without any problem, but when I am trying to debug nodejs running in docker with docker-compose I am facing a unbreakable wall. Phpstorm is connected to debugger inside docker container, but it doesn't pause on breakpoints. I think that may be some problem with path mappings. Sadly I did't find any clues how to change it and where. I will share my configuration, maybe somebody faced similar problem and would help me.

0
11 comments

Please can you provide screenshots of your Node.js Run configuration and Docker container settings?

0
Avatar
Permanently deleted user

 

"start:dev": "nodemon --debug=5858 --exec ts-node -- ./src/index.ts"

This command is used in start.sh script which overwrites CMD command in docker-compose config file.

As you can see on the last screenshot, I can connect to debugger without any problem. I can even browse typescript files on the docker container, but it doesn't stops on breakpoints. With --debug-brk flag, after connecting to debugger, it was stopped at first line and I was able to see that in Phpstorm. Thanks for answer.

0

Breakpoints won't work when using --debug , please change it to --debug-brk . With --debug-brk Node.js stops at the entry point of your app and the debugger has enough time to register breakpoints for code locations.
If Node.js is started with the --debug, it does not stop execution at the entry point, and the debugger might come too late in registering breakpoints, so they won't be hit.

0
Avatar
Permanently deleted user

I tried that before, sadly it didn't help. I found workaround (didn't tried yet), but this is not a convenient solution, so I prefer debugging on my local machine for now. Any other ideas?

Local machine:

Docker container:

0

Hmm... your configuration is rather non-trivial (nodemon + ts-node+ docker, plus everything is run using scripts). So far, I have no idea what's going on. From your screenshots it seems that ports are correctly forwarded. Did you try pre-compiling Typescript instead of using ts-node? Also, did you try using Node remote interpreters (https://www.jetbrains.com/help/webstorm/2017.1/running-and-debugging-node-js.html#node_docker_run_debug)?

0
Avatar
Permanently deleted user

Sorry for the long absence, I had many things to do and I did not have time to check the thread.

I did not try with pre-compiling nor remote interpreters. I would like to avoid pre-compilation, but if that help, it is acceptable solution. I will write how it went. 

0
Avatar
Permanently deleted user

About remote interpreter in docker container. I think it could work, because like I mentioned before, it works on localhost. One thing which stops me from that solution is inability to use it with docker-compose (or I did not find a way to do that), which will have negative inpact on time needed to setup development environment.

Precompiling helped partially. I could set breakpoint in generated javascript file but not in ts file.

To exclude that this is not a problem with IDE, I tested my configuration with pre-compiled typescript in Visual Studio Code... It works, it pauses on breakpoints without any problems and configuration took about one minute. So It looks like Phpstorm can not detect *.js.map files. In VSCode I had to set "localRoot" and "remoteRoot" paths (there are no such properties in remote debug configuration in Phpstorm/Webstorm) and it just worked. You can check out configuration below:

package.json scripts (docker container starts with "npm run dev")

VSCode debug configuration:

Is there any workaround? How can I solve that problem?

0

Remote debugging with sourcemaps only works if sources are inlined (inlineSources=true in tsconfig.json). Also, what Node.js version do you use?

0
Avatar
Permanently deleted user

I had to remove 

"sourceMap": true

from tsconfig.json and add:

"inlineSources": true,
"inlineSourceMap": true,

It works now! Thanks for help Elena :)

1

Great, thanks for update!

0

Remote debugging with sourcemaps only works if sources are inlined (inlineSources=true in tsconfig.json). Also, what Node.js version do you use?

Thanks for this Elena, I have been trying to figure out how to fix this issue all day today. It was hitting breakpoints in some instances and in others not. Once I set the source maps to include it all worked as expected.

0

Please sign in to leave a comment.