调试typescript程序时,VS Code忽略断点

时间:2017-09-12 07:29:11

标签: debugging typescript visual-studio-code

我在打字稿上有一个hello world程序:

function say(msg: string) {
    alert(msg);
    for (let i:number=0;i<10;i++)
        document.write(i+"<br/>");
}
var msg:string="hello typescript world!";
say(msg);

此代码位于src文件夹中。当我运行编译器(tsc)时,它成功生成* .js和* .map文件并将它们放在src文件夹中。此外,项目根目录中还有index.html

<html>
<body>
<script type="text/javascript" src="src/hello.js"></script>
</body>
</html>

但是当我在chrome中运行调试会话时,我的断点会被消息

忽略
  

忽略断点,因为找不到生成的代码(源映射   问题?)

在Web服务器日志中,我可以看到以下行:

  

&#34; GET /src/hello.js.map" &#34;未定义&#34;

tsconfig.json:

{
  "compilerOptions": {
    "sourceMap":true,
    "target": "es5",
    "module": "commonjs",
    "noImplicitAny": false
  }
}

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Debug in Chrome",
            "url": "http://localhost:8080",
            "webRoot": "${workSpaceRoot}"
        }
    ]
}

更新: 当尝试使用chrome调试工具设置断点时,它会在断点处停止,但不会显示我的js / ts代码:
断点补充说 breakpoint added

达到了断点 breakpoint reached

2 个答案:

答案 0 :(得分:0)

看起来VS代码存在问题。我使用完全相同的launch.json,tsconfig.json和源代码启动了新项目,并且在chrome中调试好了!然后我将所有内容复制到我的初始项目中,现在它调试也好。

答案 1 :(得分:0)

转到设置(单击“F1”)并禁用“启用Javascript源地图”选项。