Ts-node: Breakpoints don't work

Created on 9 Feb 2019  Â·  19Comments  Â·  Source: TypeStrong/ts-node

Hi guys, I faced a very strange problem. Let me know if this repo is the wrong place to post this question because I really don't realize what kind of problem is this.
I have two working PC and one of them stop breaking on the breakpoints in one day. Another PC works properly the same as before.
I tried to reinstall Node.Js, ts-node and then even hard reset for windows (I use Windows) but without any success.
Then I thought that probably issue in my project and I tried to clone hello world project from google tutorial and I found that I still can't debug with it!
So basically I successfully run an app on my port but breakpoint won't hit. This stop working in VS Code, in WebStorm and even Chrome debugger.
This is how I run an app: "C:\Program Files\nodejs\node.exe" --inspect --require ts-node/register C:\Projects\node-typescript-starter-master\src\index.ts
Then I opened dev tools from chrome and I see this:
image
Then I pressed "inspect" and I see message in console:
Debugger attached. Debugger listening on ws://127.0.0.1:9229/8bae9408-867c-4278-9148-b6c90b35a8ae For help, see: https://nodejs.org/en/docs/inspector Debugger attached.
This is the next window. Seems like I missing any files overhere.
DevTools

Does this mean that something is wrong with my file mapping ?
Please, let me any suggestion what can be a problem.

Most helpful comment

Are you using docker? If so, this comment helped to resolve this issue for me:

https://github.com/Microsoft/vscode-recipes/issues/187#issuecomment-483814483

This shows that hitting breakpoints should work as well, so there might be something else going on with your actual repository that prevents breakpoints from being hit.


info on my setup (sharing all of it just to be sure)

I'm using vscode 1.42.0, node 13.8 (from dockerhub), ts-node 8.6.2

My app is started using the following line:

export TS_NODE_PROJECT=tsconfig.json; export TS_NODE_FILES=true; node --nolazy --inspect=0.0.0.0:9229 -r ts-node/register ./src/index.ts

my tsconfig.json looks like the following:

{
    "compilerOptions": {
        "esModuleInterop": true,
        "strict": true,
        "lib": ["ES2020"],
        "types": ["node"],
        "sourceMap": true
    },
    "files": ["./src/**/*"]
}

my launch.json looks like the following:

jsonc { "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "Docker: Attach to Node", "sourceMapPathOverrides": { "/usr/src/app/*": "${workspaceRoot}/*" }, "port": 9229, "protocol": "inspector" // probably not needed here since vscode should resolve this automatically, even when using ts-node (Haven't tested it yet though) } ] }

All 19 comments

@Neustart I am in the same boat, on Mac. I have been tracing and trying just about every suggestion from https://github.com/TypeStrong/ts-node/issues/537, to no avail. I've also tried all sorts of tsconfig.json tweaks (such as inline source maps, outDir configuration), etc etc. It seems ts-node is just not wired up to be able to inspect the files, but I have not yet figured out why the debugger can attach then have no files to debug. Would love to figure this out!

https://blog.june07.com/nim-custom-devtools-url explains a solution to this. Often the problem is due to breaking changes with DevTools. Using NiM allows you to lock the DevTools version whilst still using the most recent version of Chrome.

Facing the same issue with the VS Code debugger.
It just doesn't hit breakpoints.

Facing the same issue with the VS Code debugger.
It just doesn't hit breakpoints.

@levrik Did you try https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj

@june07 I want breakpoints directly in VS Code... not an external solution.
Breakpoints are working fine when not using ts-node and just tsc.

I also have this problem. Cannot hit breakpoints in VSCode using ts-node. Have tried basically all possible configurations of tsconfig.json and launch.json as well as this module's options. What "just works" is manually compiling the source with the regular TypeScript compiler.

@rnegron Can you try disabling smartStep and see if that fixes the problem?

We were talking about weird VSCode debugger behavior the other day: https://github.com/TypeStrong/ts-node/issues/937

@cspotcode Thanks for your suggestion. Unfortunately, I did not have smartStep enabled. I tried it again with that option explicitly disabled but it didn't work. Also went ahead and tried with the new VS Code JavaScript debugger but still no stopping on breakpoints.

@rnegron bummer, it was worth a shot.

Do you have a minimum reproducible example for us to try on our machines?
What is your version of node and VSCode?

@cspotcode I attempted to make a very minimal version of the affected repository's structure with a contrived example here: https://github.com/rnegron/ts-node-breakpoints-example

However, breakpoints are working in that repository, even though they are not perfect since the debugger seems to halt on the line after the breakpoint. You will notice that the code is in JavaScript, since we are currently experimenting with a migration to TypeScript. Obviously, the real repository is much larger and there are a lot of module imports happening. Could that have anything to do with it?

@rnegron Without a reproduction, I really don't know. I would guess that it's not about the size of the repository; it's about something specific that is happening in your real repo that is not in your reproduction.

@cspotcode I will continue to debug this and report back if I find anything. Thanks!

Are you using docker? If so, this comment helped to resolve this issue for me:

https://github.com/Microsoft/vscode-recipes/issues/187#issuecomment-483814483

This shows that hitting breakpoints should work as well, so there might be something else going on with your actual repository that prevents breakpoints from being hit.


info on my setup (sharing all of it just to be sure)

I'm using vscode 1.42.0, node 13.8 (from dockerhub), ts-node 8.6.2

My app is started using the following line:

export TS_NODE_PROJECT=tsconfig.json; export TS_NODE_FILES=true; node --nolazy --inspect=0.0.0.0:9229 -r ts-node/register ./src/index.ts

my tsconfig.json looks like the following:

{
    "compilerOptions": {
        "esModuleInterop": true,
        "strict": true,
        "lib": ["ES2020"],
        "types": ["node"],
        "sourceMap": true
    },
    "files": ["./src/**/*"]
}

my launch.json looks like the following:

jsonc { "version": "0.2.0", "configurations": [ { "type": "node", "request": "attach", "name": "Docker: Attach to Node", "sourceMapPathOverrides": { "/usr/src/app/*": "${workspaceRoot}/*" }, "port": 9229, "protocol": "inspector" // probably not needed here since vscode should resolve this automatically, even when using ts-node (Haven't tested it yet though) } ] }

I have an issue with ts-node not stopping on breakpoints in VS Code, but only if those breakpoints are in the files imported by the main file. If the main file has any breakpoints after the import statements, breakpoints inside imported code are triggered just fine.

@romankozak As far as I can tell, if I want breakpoint to be triggered in imported files, I need to add a breakpoint to my main file before code from any imported files is called. This appears to be a VSCode bug. Everything works correctly in Chrome/Edge DevTools.

I created a branch where I have a code sample with the debugger configured. Hopefully using this as a reference makes it a little bit easier to discuss what works and what doesn't. https://github.com/TypeStrong/ts-node-repros/tree/vscode-debugging

@cspotcode thank you for the sample. I think you are right that this is VSCode bug. I've tried to workaround by compiling the typescript code with tsc first and then running it - with this approach, breakpoints were triggered correctly in the test project, but in the other project only part of the time.
This doesn't repro when running code thru mocha test with ts-node, so this could an alternative approach to having breakpoint in the main file for VS Code users.

I wonder if it does not repro with mocha because mocha loads all the files
first, then fires the callbacks later. Perhaps this delay gives the
debugger enough time to register breakpoints.

On Tue, May 12, 2020 at 4:48 PM Roman Kozak notifications@github.com
wrote:

@cspotcode https://github.com/cspotcode thank you for the sample. I
think you are right that this is VSCode bug. I've tried to workaround by
compiling the typescript code with tsc first and then running it - with
this approach, breakpoints were triggered correctly in the test project,
but in the other project only part of the time.
This doesn't repro when running code thru mocha test with ts-node, so this
could an alternative approach to having breakpoint in the main file for VS
Code users.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/TypeStrong/ts-node/issues/778#issuecomment-627585441,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAC35OCB3PDYFT54J2KA4CDRRGYZFANCNFSM4GWLAV7A
.

Also happens with IntelliJ / Webstorm (2020.2+) + Mocha.

Oddly, the breakpoints in Mocha test files will be hit, but all subsequent required TS files do not get breakpoints hit. Spent days tweaking configs, trying different combos, etc. to no avail.

I switch to JEST + TS-JEST and don't have any of the same issues.

@Gameghostify Thanks, it worked for me as also found here: https://medium.com/@dupski/debug-typescript-in-vs-code-without-compiling-using-ts-node-9d1f4f9a94a

Was this page helpful?
0 / 5 - 0 ratings