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

浪尽此生 提交于 2019-12-11 17:52:51

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/52778424/vscode-debugger-not-hitting-breakpoint-if-is-not-in-the-current-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!