如果不在当前文件中,VSCode调试器未达到断点 [英] VsCode debugger not hitting breakpoint if is not in the current file

查看:76
本文介绍了如果不在当前文件中,VSCode调试器未达到断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望调试器能够击中断点,而不管断点在堆栈中的什么位置.

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

有2个文件:

start.ts

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

Transform.ts

Transform.ts

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

使用此配置:

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

如果我在 start.ts 文件中运行调试器,我希望可以击中 Transform.ts 中的断点,但不会.

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

但是如果我先将调试器放在 start.ts 中,那么也会击中 Transform.ts 中的调试器.

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?

推荐答案

我能够重现此行为.看起来像是一个竞争条件:我想断点是无法加载的,除非加载 Transform.ts ,并且一旦加载 Transform.ts ,VS Code便开始设置程序继续执行时的断点.如果我将 start.ts 更改为:

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.

考虑对此问题进行评论.我想知道是否有一个API, ts-node 可以用来在加载每个TypeScript文件之后给调试器时间来安装断点.

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.

这篇关于如果不在当前文件中,VSCode调试器未达到断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆