-
-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VSCode Debugging #46
Comments
You're going to have to provide more information for me to replicate. I personally don't even use VSCode, so have no idea what this issue even means or where to start. How do I reproduce it? It's unlikely it's an issue with |
@blakeembrey absolute; so its rather simple. do What IDE you use? VSCode seems like a obvious TS user IDE. |
I've hit this issue today, though I'm not using the latest revision and it seems like there have been some changes to source map generation lately. The main problem here I think is that VSCode seems to require access to a
so that's a dead end unless someone adds support for it in VSCode. |
Yeah, it sounds like this is unlikely to ever work then. That's unfortunate. VSCode would have to hook into |
I am using ts-node to run mocha. I can get debugging to work in Webstorm although there are issues:
Is there some way to verify that the source maps generated in memory are correct when running mocha? |
Tried setting both inlineSourceMap and inlineSources to true in tsconfig.json but exact same behaviour in Webstorm. |
The source maps are all correct, I believe the issue is what I mentioned above - the fact they don't have access to the source maps. If there's some way to make access possible, I'll investigate it. Perhaps the source map location could be absolute and I could write the files into a temporary directory during execution. |
Looks like things have changed- https://code.visualstudio.com/docs/editor/debugging:
I've tried turning on these options but breakpoints still don't work for me. My config: {
"version": "0.2.0",
"configurations": [
{
"name": "Test",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": ["--require", "ts-node/register", "test/table.test.ts"],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": true,
"outDir": null
}, |
@arolson101 I believe you misunderstand. There's no difference. TypeScript still does not have access to the source maps of |
Coming back to this, I use VS Code now and often use the debugging feature. However, I recommend you compile the JavaScript files with source maps and execute those directly instead. It's pretty simple with VS Code to set up a CLI task that watches and compiles using |
😒 |
Does this mean no translated stack traces from node when an uncaught exception is thrown whilst debugging in vscode? |
No. How are you debugging in vscode? |
Without using ts-node, obviously works fine but I switched to ts-node so I could have proper stack traces on a crash but then the debugger doesn't pick up the breakpoints. So I have both configs in my launch.json and I just comment in/out the relevant one depending if I want to debug or run |
Did you read this issue? |
If you want to re-map errors according to source maps, I'd recommend checking out https://github.com/evanw/node-source-map-support. |
I did read it, I assumed by " I recommend you compile the JavaScript files with source maps and execute those directly instead" you meant don't use ts-node. I did look at that project before but looked like far more effort to setup compared to ts-node, i'll stick with switching configs for now |
Yes, that's exactly what I recommend. I'm not sure what you're asking now, sorry. That project is only one line - you asked for source map support with stack traces? |
yes will take another look thanks |
'm coming back to this after a bit, have a few comments since first started...
@blakeembrey Are you not saving the files to disk at all? I know
@enlight you should check this out, looks like it has it now microsoft/vscode#2803
@blakeembrey would be worth considering building this into ts-node.
@blakeembrey so I have to ask if this is necessary what is the point of this project? ;) |
No, that's the entire point. Babel does it as a cache, but a cache doesn't help much with TypeScript since it's not a single file cache and requires the entire project loaded anyway for compilation errors. In
It has been since the first release.
Lots of people have different use-cases to you and may not use an IDE debugger. For instance, I've never really used it (for something I'd use |
Thanks for clarifying those details! I'm just trying to understand the use cases for the project given the hurdles. I hate having to have tool and workflow for build/etc when this theoretically could be done on the fly 😞 |
Understandable - I think it'd be valuable to check if generating the source map contents into a temp file would fix this. I'll make that change when I get a chance, probably just rewriting contents into |
@blakeembrey awesome!! Let me know and i'll give it a try on my demo project I'm working on. For reference, on the Babel page you can see |
Any progress on this? I'm using the CLI with nodemon and ts-node + attach in VSCode |
I went ahead and built #148. Feel free to test it and let me know if it works. I have a suspicion that it won't though. VS Code needs to be able to discover the source map file. If it could do that, it should have been doing that already with previous versions. The issue is that VS Code needs access to both |
@blakeembrey couldn't you inline the sourcemaps? |
@cspotcode I had to replace "runtimeArgs" with "args" to make it work and add node: 8.9.4 |
For debugging protractorJS tests this works: {
"type": "node",
"request": "launch",
"name": "Working thru node",
"program": "${workspaceFolder}/node_modules/.bin/protractor",
"args": [
"./jasminejs/protractor.conf.js",
"--directConnect=true"
],
"protocol": "inspector",
"sourceMaps": true,
"console": "internalConsole",
"outputCapture": "std"
} The only JS file - is tsconfig.json:
|
Can I strongly suggest (/beg) that the 'current, best' way to setup VSCode debugging with ts-node is described in the main README? VSCode is very widely used for Typescript dev. An official 'Hello World' debugging setup would give ts-node much more traction with devs I expect... If they can't get it working straight away with step-through debugging - You've lost 80% of folks right there... Which is to say - I've tried several stated solutions from above, and elsewhere, but can't get breakpoints to work reliably (if at all) with ts-node. I guess I will head down the "tsc --watch" path to get a vague equivalent to ts-node... @cspotcode - Any chance you could pop up a complete, working 'Hello World' project with debugging support and VSCode config on github? I'll send you $20 for your trouble. Seriously... |
I can check but I'm not sure it should be very complicated to get started. Just add |
Just verified it working locally by creating a new project. All I did is below. Can someone confirm this? {
"type": "node",
"request": "launch",
"name": "Launch Program",
"runtimeArgs": [
"-r",
"ts-node/register"
],
"args": [
"${workspaceFolder}/index.ts"
]
} |
I'm still getting patchy breakpoint behaviour. It seems to work reliably in the primary file (index.ts), but not in other imported files. Interestingly, it works somewhat more reliably after a restart of VSCode. Breakpoint debugging is simply not working reliably for me I'm afraid. Is any special content required in tsconfig.json? And/Or is it necessary for it to be non-existant? |
@peternann Can you share the configuration(s) you have tried? Also possible node.js and |
Works well for me on node |
UPDATE: well, breaks work in an initial file ( |
Created reproduction repository - here:
node UPDATE: the funny thing is, that it works exactly the same with generated .js files (break hits in {
"type": "node",
"request": "launch",
"name": "node",
"program": "${workspaceFolder}/lib/index.js",
"preLaunchTask": "build",
"sourceMaps": true
}, So now it looks like vscode\TS issue? Or tsconfig should be tweaked... I'm confused UPDATE2: verified on my old project with UPDATE3: left a comment here as well.. |
So it looks like vscode bug... superannoying! |
Installed |
@s-KaiNet nope, it still doesn't work for me though (angular-cli protractor and vscode). Tests are launching, but breakpoints are greyed-out with a message |
@Kamilius hmmm strange... If the answer is yes to both questions, then I don't know the reason why it's still doesn't work for you. For me, 1.20 automagically fixed all issues. |
Just a quick update for people. Looking through the bug mentioned by @s-KaiNet, if you're using VS Code 1.21.1, you will need to follow the workaround. The fix is in place for the next build, but unless they release a 1.21.2, we won't see the fix until 1.22. I can confirm that I have everything working as expected in 1.22-insiders with the following launch.json
@Kamilius I suggest trying your project using VS Code Insiders build, just to see if it works as expected. |
@s-KaiNet, I don't know if it worked previously, as I've just started writing and running those tests onPrepare() {
require('ts-node').register({
project: './e2e/tsconfig.e2e.json'
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
} @davidwesst workaround you've suggested, for Here's my {
"type": "node",
"request": "launch",
"name": "ng e2e",
"cwd": "${workspaceFolder}/angular",
"program": "${workspaceFolder}/angular/node_modules/protractor/bin/protractor",
"protocol": "inspector",
"args": ["${workspaceFolder}/angular/protractor.conf.js"],
"stopOnEntry": false,
"sourceMaps": true,
"runtimeExecutable": "~/.nvm/versions/node/v7.9.0/bin/node",
"runtimeVersion": "7.9.0",
"outFiles": [
"${workspaceFolder}/**/e2e/**/*.js"
]
} Version of node is set to
|
@Kamilius -- My apologies as I didn't see this until just now! Well, 1.22.1 is already out, so hopefully that resolves the issue in the long-term. The answer I found for the breakpoint thing was you needed to follow the following to "reapply all breakpoints":
Again, hopefully this is fixed in the new version of Code that is out, but that was my little workaround. |
I am still having no luck with this. I gave up on my old project. Figured it had something weird. As requested by @blakeembrey, here is my launch config:
Yes, that is byte-for-byte what was suggested. Breakpoints in the top file (index.ts) work fine, (Even though they report "Breakpoint ignored because generated code not found (source map problem?)." The other breakpoints show the same text on hover, but are grayed out and the breakpoint circle is empty. They go gray as soon as I launch, by the time they hit my test breakpoint in the top file. The disable/reenable/Reapply All tricks do not work for me. This is driving me bananas. Does the contents of tsconfig.json matter? Here's mine right now after minimizing it:
'tsc' completes happily, silently Any new ideas out there? |
@blakeembrey Thanks for the solution it works ! |
For attaching, the process is pretty much the same. package.json:
and in launch.json the typical
|
when start by without nodemon ,the breakpoint is ok |
I just paste here couple solutions that work nicely: Launch
Attach With Foreverthis is particularly cool, as the forever automatically restarts the process and debugger automatically re-attaches 👍
And the command
|
{
"name": "TS Node",
"type": "node",
"request": "launch",
"env": {
... whatever
},
"args": ["./src/server/index.ts"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector"
} This did not work for me...the only think that has worked is manually compiling the typescript files and then manually running the debugger |
thank you very much |
Hey @blakeembrey, do you know if this is still working correctly? {
"launch": {
"configurations": [
{
"name": "Debug Current",
"type": "node",
"request": "launch",
"args": [
"${fileBasename}"
],
"runtimeArgs": [
"-r",
"ts-node/register"
],
// "sourceMaps": true,
"cwd": "${fileDirname}",
"protocol": "inspector",
"outputCapture": "std",
},
],
"compounds": []
}
} EDIT: It does work, if I place a breakpoint in the file that is run, strangely. Any idea? |
nevermind, it seems to be related to microsoft/vscode-chrome-debug-core#533 |
If anybody lands here, I'd advise using ts-node-dev example: https://gist.github.com/GuillaumeDesforges/bf7383f8403e1683b2b9467db3964185 |
Thank you @GuillaumeDesforges I tried like a 1000 different ways and this was the only one that worked for my use case 😓
|
VSCode will not recognize any breakpoints hit.
The text was updated successfully, but these errors were encountered: