How to connect the WebStorm debugger to a dockerized NestJS project?

I have a Nestjs application running in Docker in debug mode as follows: nest start --debug 0.0.0.0:9229 --watch
When checking the container, debugging runs correctly and I can connect when I start the debugger, as when I check the container logs each time I connect, the message “Debugger attached.” appears. The problem arises when I add a breakpoint and execute an endpoint from my API. WebStorm does nothing; it does not initialize from my breakpoint. I have tried several configurations to see if it could be due to something related to the paths, but I get no results.  

0
5 comments

The debug configuration looks fine. Could you check if you can debug your application using chrome://inspect?
 

0

Elena Pogorelova I am using Edge and connected via edge://inspect, and I was able to connect. So far, everything is normal because I can also do this in WebStorm. The difference is that in Edge I can only debug the transpiled files from my project. I am not 100% sure, but I think there is a problem with source mapping. I think WebStorm cannot link remote files with local files.

I don't know if this screenshot will be helpful, but I notice that in the debugger's scripts section, I only see the node modules from my local project “linked,” while those from my container project are linked to my project root. 
 

0

I found the problem. When we run a NestJS application, a directory with our transpiled files is generated. All source mapping falls into the folder generated by NestJS. When the debugger tries to run, it manages to connect, but it doesn't know how to correctly map the container code with the code we have locally, since it looks for exactly the same paths. To solve this, you just need to generate a build locally and the debugger will automatically map the files correctly.

0
Glad to hear that the issue is solved. Thanks for investigations!
0

You can try adjusting your WebStorm debugger settings — make sure the host is set to 0.0.0.0, and use port 9229 to match your container. Also, check that the source mapping paths in WebStorm match your Docker container’s working directory. That usually fixes breakpoint issues.

0

Please sign in to leave a comment.