Skip to content
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

Breakpoints don't work #778

Closed
kirill-kostenetskyi opened this issue Feb 9, 2019 · 23 comments
Closed

Breakpoints don't work #778

kirill-kostenetskyi opened this issue Feb 9, 2019 · 23 comments

Comments

@kirill-kostenetskyi
Copy link

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.

@kirill-kostenetskyi kirill-kostenetskyi changed the title Breakpoint won't hits Breakpoints don't work Feb 9, 2019
@rmckeel
Copy link

rmckeel commented Apr 11, 2019

@neustart I am in the same boat, on Mac. I have been tracing and trying just about every suggestion from #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!

@june07
Copy link

june07 commented May 21, 2019

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.

@levrik
Copy link

levrik commented May 24, 2019

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

@june07
Copy link

june07 commented May 24, 2019

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

@levrik
Copy link

levrik commented May 28, 2019

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

@rnegron
Copy link

rnegron commented Jan 17, 2020

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.

@cspotcode
Copy link
Collaborator

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

We were talking about weird VSCode debugger behavior the other day: #937

@rnegron
Copy link

rnegron commented Jan 17, 2020

@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.

@cspotcode
Copy link
Collaborator

@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?

@rnegron
Copy link

rnegron commented Jan 17, 2020

@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?

@cspotcode
Copy link
Collaborator

@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.

@rnegron
Copy link

rnegron commented Jan 17, 2020

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

@Gameghostify
Copy link

Gameghostify commented Feb 7, 2020

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

microsoft/vscode-recipes#187 (comment)

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:

{
	"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)
		}
	]
}```

@romankozak
Copy link

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.

@cspotcode
Copy link
Collaborator

@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

@romankozak
Copy link

@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.

@cspotcode
Copy link
Collaborator

cspotcode commented May 12, 2020 via email

@tcf909
Copy link

tcf909 commented Mar 1, 2021

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.

@eytienne
Copy link

@centraldogma99
Copy link

centraldogma99 commented Sep 18, 2021

I was also having this issue, but I solved it with this:

Below is my before/after launch.json
(using VSCode 1.59.0)

Before

"version": "0.2.0",
  "configurations": [
    {
      "name": "ts-node",
      "type": "pwa-node",
      "request": "launch",
      "runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
      "protocol": "inspector",
      "args": ["--ts-node"],
      "program": "${workspaceFolder}/app.ts",
      "cwd": "${workspaceRoot}"
    }
  ]

After

"version": "0.2.0",
  "configurations": [
    {
      "name": "ts-node",
      "type": "pwa-node",
      "request": "launch",
      "runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
      "protocol": "inspector",
      "args": ["${workspaceFolder}/app.ts", "--ts-node"],
      "cwd": "${workspaceRoot}"
    }
  ]

I removed program property and moved its value into args and it worked.

I don't know why, but now vscode debugger hits breakpoints correctly

@cspotcode
Copy link
Collaborator

Thank you for sharing your configuration. Do you have a few minutes to compare your configuration against the one in our documentation? If our documentation is incorrect, incomplete, or confusing, I would definitely like to make the necessary corrections or improvements to help other users.

@cspotcode
Copy link
Collaborator

@cspotcode
Copy link
Collaborator

I have tested the debug configuration in our docs to confirm that it works with breakpoints.
Here is where I did the testing:
https://github.com/TypeStrong/ts-node-repros/tree/vscode-debugging

I tweaked our documentation here: #1466

Closing as I believe no further action is required. Improvements to our documentation can be submitted as pull requests, and Discussions can be used for more open-ended discussion and tech support around debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests