如何使用 ts-node 和 Chrome 调试 TS?

How do you debug TS with ts-node and Chrome?

提问人:jcollum 提问时间:6/17/2023 更新时间:6/17/2023 访问量:92

问:

脚本:

(async () => {
  debugger;
  const go = await showWarning();
  if (go) {
    const startTime = process.hrtime.bigint();
  // more code here
  }  
})(); 

命令行:

NODE_OPTIONS=--inspect-brk npx ts-node --transpileOnly  \ 
testing/perf/src/run.ts

TSconfig:

{
    "include": [
    "src/**/*"
  ],
  "compilerOptions": {
    "target": "es2022",
    "resolveJsonModule": true,
    "esModuleInterop": true
  },
  "exclude": [
    "node_modules"
  ]
}

过程:

  1. 打开 Chrome 检查选项卡
  2. 从命令行启动脚本
  3. 检查器停顿了一下,理应如此
  4. 将断点放在行下,点击“恢复”按钮debugger
  5. 脚本运行,完全错过了行和断点debugger

Chrome 有权访问脚本文件并加载它。我可以在调试器中看到脚本,但它永远不会就此停止。我的 TSconfig 可能有问题,但我不知道是什么。我找到的所有答案都是针对IDE调试器的,我不想使用它(如果你真的想知道,我会告诉你,但这似乎偏离了主题)。

typescript google-chrome 调试 ts-node

评论


答: 暂无答案