简体   繁体   中英

VsCode debugger not hitting breakpoint if is not in the current file

I would expect debugger to hit breakpoint regardless where the breakpoint is in the stack.

Having 2 files:

start.ts

import { transformString } from './Transform'
transformString('foo')

Transform.ts

export const transformNitroToClip = () => {
  // some code
  => my breakpoint
  // some code
}

With this configuration:

  {
      "type": "node",
      "request": "launch",
      "name": "Single File",
      "args": ["${relativeFile}"],
      "runtimeArgs": [
          "-r",
          "ts-node/register"
      ],
      "cwd": "${workspaceFolder}",
      "internalConsoleOptions": "openOnSessionStart",
      "sourceMaps": true,
      "outFiles": [ "${workspaceRoot}/dist/**/*.js" ]
  }

If I run the debugger in start.ts file I would expect the breakpoint from Transform.ts to be hit but it's not.

But if I put a debugger in start.ts to be hit first then the one from Transform.ts is hit as well.

Is there any workaround to not be required to have a debugger in the main file in order to trigger the other ones?

I was able to reproduce this behavior. It looks like a race condition: I presume that the breakpoint cannot be set until Transform.ts is loaded, and once Transform.ts is loaded, VS Code is racing to set the breakpoint as the execution of the program continues. If I change start.ts to:

import { transformString } from './Transform'
setTimeout(() => transformString('foo'), 100);

then everything works. That might be an adequate workaround.

Consider commenting on this issue . I wonder if there is an API that ts-node can use to give the debugger time to install breakpoints after loading each TypeScript file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM