ts-node: Breakpoints don't work

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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 23

Most upvoted comments

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

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:

{
	"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 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 .

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

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