[英]vscode TypeScript debugging in Angular project with F5. Not breaking or in a wrong spot
我读到了许多相关的问题,其中调试不起作用。 就我而言,它有效,但是“很奇怪”。 我在一行代码中设置了断点,但它在完全不同的行中断了。 我觉得它与源地图有关,但不确定是什么。
环境:
使用CLI和ng new
生成的项目
为F5启动器(launch.json)添加了以下配置:
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
}
]
这是app.component.ts
代码:
import { Component, OnInit } from '@angular/core';
import { isUndefined } from 'util';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = "Portal";
ngOnInit(): void {
this.test();
}
test() {
const person = { FirstName: "John" };
person.FirstName = "sf";
let b = "test string";
b = "other string";
}
}
在类似b = "other string"
设置断点
在终端ng serve
照常开始单击F5-Chrome打开并显示主屏幕。
问题1: Chrome根本无法刹车。
刷新Chrome页面时-断点被击中,但位置错误。 它可以在ngOnInit
或在Component
行中,相当“随机”。
问题2:中断发生在错误的行上
有什么办法可以使这项工作,以便我可以使用VSCode轻松进行设置和调试吗?
很难说出为什么您的设置行为异常。 我还使用VSCode调试Angular应用程序,并且我的设置运行良好,我将在这里共享它,希望对您有所帮助。
launch.json
如下所示 { "version": "0.2.0", "configurations": [ { "type": "chrome", "request": "launch", "name": "Launch Chrome", "url": "http://localhost:4200", "webRoot": "${workspaceRoot}", "sourceMaps": true, "userDataDir": "${workspaceRoot}/.vscode/chrome", "runtimeArgs": [ "--disable-session-crashed-bubble" ] }, { "name": "Attach Chrome", "type": "chrome", "request": "attach", "url": "http://localhost:4200", "port": 9222, "webRoot": "${workspaceRoot}", "sourceMaps": true } ] }
ng serve
您的角度应用ng serve
现在,您应该能够开始调试应用程序(使用F5
),并且所有断点都可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.