nx: @nrwl/nest VSCode breakpoints no longer working
Current Behavior
I am getting unbound breakpoints in VSCode when trying to debug Nest with a fresh npx create-nx-workspace@latest. This just suddenly started occurring over the past 3 days with no real cause that I can narrow it down to.

Though creating a Nest app using @nestjs/cli with npx @nestjs/cli@latest new and serving with nest start --debug with the same launch.json seems to work. It seems to be something specific to Nx.
Expected Behavior
Breakpoints should work
GitHub Repo
No response
Steps to Reproduce
- Created a fresh Nest integrated monorepo using
npx create-nx-workspace@latest - Launch VSCode with all extensions disabled via
code . --disable-extensions - Add the following .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "nest",
"type": "node",
"request": "attach",
"port": 9229,
"restart": true
}
]
}
- Set a breakpoint,
nx serve apiand start VSCode debugger
Nx Report
Node : 18.13.0
OS : win32 x64
npm : 8.19.3
nx : 15.6.3
@nrwl/angular : Not Found
@nrwl/cypress : Not Found
@nrwl/detox : Not Found
@nrwl/devkit : 15.6.3
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 15.6.3
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.6.3
@nrwl/js : 15.6.3
@nrwl/linter : 15.6.3
@nrwl/nest : 15.6.3
@nrwl/next : Not Found
@nrwl/node : 15.6.3
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/rollup : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/webpack : 15.6.3
@nrwl/workspace : 15.6.3
@nrwl/vite : Not Found
typescript : 4.8.4
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
Failure Logs
No response
Additional Information
No response
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 24
- Comments: 52 (6 by maintainers)
Commits related to this issue
- build(api): Fix for https://github.com/nrwl/nx/issues/14708 undefined — committed to ZenSoftware/zen by ZenSoftware a year ago
- [Fix] Enable debugger for a `nestjs` project in a `nx` monorepo See: [@nrwl/nest VSCode breakpoints no longer working](https://github.com/nrwl/nx/issues/14708) — committed to ratasorin/itec2022 by ratasorin a year ago
- [Fix] Enable debugger for a `nestjs` project in a `nx` monorepo See: https://github.com/nrwl/nx/issues/14708 — committed to ratasorin/itec2022 by ratasorin a year ago
Problem still persists in the latest (15.8.5) version.
It seems that sources array in a generated source map have wrong relative path.
As a workaround, the following
webpack.config.jsfixes the issue and outputs correct source map same as before it was broken:After upgrading from Nx 17.1.3 to v17.2.X
config.devtoolsetted tofalseby default.Config with working breakpoints:
Bump this is a critical issue
Still a issue
经过楼上大佬的讨论 目前 仅仅修改vscode的launch.json即可运行debug,但是这仅针对于vscode调试 其他code编辑器未试
nx版本:16.3.x
vscode:launch.json配置
其中backend可以替换成nx工作区内各自项目名称
Continues to fail in 16.3.2.
Bump, still an issue in Nx 17.0.3
for the love of god its been months why are we still doing a workaround for a basic necessary feature can this be resolved already?
Thank you @gdraganic. With your workaround and the information in @pmosconi’s comment, I was able to get this resolved in our workspace on Nx 15.9.2. We’re in the middle of migrating from 14 to 15 right now and this bit us (just now realizing 16 came out a few hours ago 😭). Usually during major migrations I will go ahead and generate a “test app” with the newer schematics for each of our application types (Angular, Nest, React, etc.) just to make sure we keep up with any changes to project configurations that migrations may not capture, so thankfully I had already added the
webpack.config.jsfiles to our node projects and set everything up to point them in the relevantproject.jsonfiles.For greater convenience (we have multiple node apps), I created the below in
tools/helpers/patch-nx-source-map-paths.jswith the following contents:And modified all of our
webpack.config.jsfiles like so:Hopefully this gets addressed soon.
This worked for me. I also had to change project.json configuration adding these 2 lines that might not be present in case of upgrade from an older version:
For
nx@17.2.8thislaunch.jsonandwebpack.config.jsconfiguration did the trick for me:Also this doesn’t work not only with nest, but also with plain TS express application with executor @nx/webpack:webpack. NX 16.5.2
Still an issue in
16.4.0-beta.5cc @FrozenPandazthanks for the workaround. still an issue in 16.1.4
After reverting to Nx v15.6.2 from v15.6.3, breakpoints are working again. Something changed between 15.6.2 to 15.6.3 that breaks debugging with VSCode.
For the last version this config worked for me
Here is what worked for us , Nx 17.2.6 , thanks to everyone above 🎉
Here’s an nx 17.2.7 compatible typescript composable plugin for this (i take no credit for the actual solution – thanks for everyone else above for coming up with it!):
Adding
config.devtool = 'source-map';to the bottom of the config got my breakpoints working again. Thank you. It is very kind of you to have provided a working solution. 🎐I’m taking suggestions but writing my own webpack config seems counterintuitive
Thanks to this link, after adding this configuration I’m able to use debugger:
Reverting to 15.6.2 from 15.6.3 solved for me. The issue is that the paths in webpack are incorrect in 15.6.3
15.6.3 produces:
15.6.2
After upgrading from Nx 17.1.3 to v17.2.X this workaround no longer works for me. I’m curious if anyone has come up with a workaround that works for Nx v17.2?
Hi guys, The debugger didn’t break on breakpoints I set (only with
debugger;) and I’ve figured our the root cause for me - might help others as well: https://github.com/nestjs/swagger/issues/2496Problem seems to still persist in
15.8.1. I’m able to construct alaunch.jsonconfiguration that startsmain.tsdirectly with debugging, but that won’t include webpacks magic.sourceMapsuggestions don’t work either.Same problem here after migrating a workspace from 15.4.5 to 15.6.3.
And also fix multi-application debugging. The first app that gets built is the only one that can be debugged.
In my case it was much simpler. I am forcing the usage of the
tsccompiler, but even specifying"sourceMap": trueintsconfig.base.json(and not overriding it), the sourcemaps weren’t being generated.I just added
"sourceMap": trueto mybuildtarget, looking like this:Issue gone!
I am running Node 20.11.0 and Nx 17.2
By the way, it even works on IntelliJ IDEA and WebStorm debugger, that is what I actually use
Thanks for posting the solutions here, it’s still an issue with 17.2.8. This is what worked for me, instead of using cwd I’ve used root path this change also makes it work if the current working directory is somewhere under the project itself
you can also try that commented-out webpack-merge approach
@francobasilico debugger works with version v17.2.8 using config like you have
You will either need to patch the webpack config with a custom
devtoolModuleFilenameTemplatelike shown in the answers above (I went this route) or configure thesourceMapPathOverridesin VSCode launch.json.Any solution? The VSCode debugger doesn’t work with 16.6.0 too.
I tried upgrading from 15.9.2 to 16.2.2 and debugger is not even starting. VSCode output window says:
[error] [Extension Host] Error: Could not connect to debug target at http://localhost:9229: Could not find any debuggable targetI tried a few tweaks on project.json and launch.json but no luck…Bump
@MilanKovacic Thanks for the detailed explanation.
I was trying to get it working using the “auto attach” feature so that all you needed to do to get debugging running was to use a pre-defined task that basically ran
nx servefor that project. In my current workspace I don’t have a launch.json file and was trying to avoid having to create one.I’m generally not a big fan of having to start the app then attach the debugger as a separate manual step as you may not be able to break on the very first line of code. I’m sure that starting and attaching can be done using a single launch.json configuration, but it seemed even easier if I could simply auto-attach and then use the
nx servetarget as normal.nx 18.0.7 and node 20.11.1 Still no vscode breakpoints out of the box. This is crucial.
the following config worked for me on
nx@17.2.8launch.jsonfrom https://github.com/nrwl/nx/issues/14708#issuecomment-1905783979webpack.config.jsfrom https://github.com/nrwl/nx/issues/14708#issuecomment-1883177763For version v17.2.7.
With the following config, still doesn’t work. AM I missing somethings?
and