tsx
tsx copied to clipboard
Debugging not working in VS Code
Acknowledgements
- [X] I searched existing issues before opening this one to avoid duplicates
- [X] I understand this is not a place for seek help, but to report a bug
- [X] I understand that the bug must be proven first with a minimal reproduction
- [X] I will be polite, respectful, and considerate of people's time and effort
Minimal reproduction URL
See below
Version
v4.7.1
Node.js version
v21.6.1
Package manager
npm
Operating system
Windows
Problem & Expected behavior
I'm having the same issue as #260, but I cannot reply there as the issue is locked. Breakpoints don't work because VS Code is putting a breakpoint on the compiled and minified JS code, instead of the original TS source. To reproduce:
-
Use the
launch.jsonfile given in your documentation (either method). -
Create a simple TS file
test.ts, for example:
let x: number = 1;
console.log(x);
-
Put a breakpoint on the second line.
-
Press F5.
Instead of breaking on the original test.ts, VS Code will open a new tab with the title test.ts, except that it will be the compiled and minified JS code, as in the following screenshot:
Note also that it will print out 1 to the terminal, because it's breaking on the second (empty) line of the compiled JS code, NOT on the second line of the original TS code.
Furthermore, if I add a third line and put a breakpoint on that, then it doesn't break at all, since the compiled code only has 2 lines ( the second one being empty).
As suggested in #260, I tried setting inlineSourceMap and/or inlineSources to true in tsconfig.json, but that does not resolve the problem. That issue originally seems to have been resolved by upgrading Node from v12 to v14, but I'm using Node v21, so that does not apply to me.
Is this a bug? Or am I doing something wrong? If it's a bug, then it should be fixed, since tsx is not so useful in development if debugging doesn't work. If I'm doing something wrong, please tell me what I should do instead (and ideally also add that to the documentation, since I followed your documentation very closely and it doesn't work).
Thanks!
Contributions
- [ ] I plan to open a pull request for this issue
- [ ] I plan to make a financial contribution to this project
You're probably encountering this: https://github.com/privatenumber/tsx/discussions/464
Do you mind filing a bug report in Node.js?
@privatenumber I'm using IntelliJ to debug but I can reproduce the same problem there. Reverting to node 21.5.0 as you recommended fixes the problem.
One thing that might help is that I noticed node --loader ts-node/esm works perfectly in node 21.6.x. You might want to check out their source-code to figure out what they did differently.
Hi @privatenumber, thanks for your reply. As @cowwoc mentioned, there is no such problem when using ts-node. If I had more time, I might have pursued this further and filed a bug report in Node.js, but unfortunately this is a very busy time of the year for me, so for now I decided to just use ts-node instead, since it works well for my needs. Thanks again!
I've got the exact same issue on Node.js v21.7.1 with tsx v4.7.1, but ts-node works fine.
As per the contribution guide, please refrain from "also happening in ..." comments.
Try to add value by debugging the problem to find potential solutions.
Locking issue to direct further conversation to PRs.
No, this is not a spam.
I'm stating this issue still exist on Node.js v21.7.1, someone said this might be related to a bug introduced on Node.js v21.6+ and it was fixed on 21.7.1, so I'm just here to say on 21.7.1 this issue still presists, so it wasn't related to this bug. That's all.
Have a read first before pointing finger to someone else please.
This node.js bug https://github.com/nodejs/node/pull/51690 is fixed and seems merged in v21.7.0+. I'm here to point out this bug probably isn't related to this issue.
The issue is already acknowledged, and now we need investigation on why it's happening.
If the bug was happening in 21.6, and it's not fixed yet, I think it's expected for it to still be happening in 21.7.1. As someone that might tackle the issue in the future, sorry but I'm not sure if I find your comments helpful.
People often make claims about tsx without proof, only to leave it for a contributor to investigate and find that it's invalid. Unsubstantiated claims will be hidden as spam as they could waste other peoples time.