当前位置: 首页 > 知识库问答 >
问题:

如何使用VSCode调试Angular?

盖高畅
2023-03-14

如何配置Angular和VSCode,使我的断点工作?

共有3个答案

华煜祺
2023-03-14

有两种不同的方法。您可以启动一个新进程,也可以连接到一个现有的进程

这两个过程中的关键点是同时运行webpack开发服务器和VSCode调试器。

>

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Angular debugging session",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}"
    }
  ]
}

通过执行npm start从Angular CLI运行Webpack开发服务器

>

雨衣:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

窗户:

chrome.exe --remote-debugging-port=9222

启动。json文件将以以下方式显示:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Chrome Attach",
      "type": "chrome",
      "request": "attach",
      "port": 9222,
      "url": "http://localhost:4200/",
      "webRoot": "${workspaceFolder}"
    } 
  ]
}

在这种情况下,调试器将附加到现有的Chrome进程,而不是启动新窗口。

我写了自己的文章,用插图描述了这种方法。

如何在VSCode中为Angular配置调试器的简单说明

顾嘉纳
2023-03-14

看起来VS代码团队现在正在存储调试配方。

https://github.com/Microsoft/vscode-recipes/tree/master/Angular-CLI

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome with ng serve",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceRoot}"
    },
    {
      "name": "Launch Chrome with ng test",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:9876/debug.html",
      "webRoot": "${workspaceRoot}"
    },
    {
      "name": "Launch ng e2e",
      "type": "node",
      "request": "launch",
      "program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
      "protocol": "inspector",
      "args": ["${workspaceRoot}/protractor.conf.js"]
    }      
  ]
}
薛弘壮
2023-03-14
  1. 安装Chrome调试器扩展
  2. 创建launch.json(在. vscode文件夹内)
  3. 用我的launch.json(见下文)
  4. 创建tasks.json(在. vscode文件夹内)
  5. 用我的tasks.json(见下文)
  6. CTRLSHIFTB
  7. F5

启动。用于angular/cli的json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Launch Chrome (Test)",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:9876/debug.html",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Launch Chrome (E2E)",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
      "protocol": "inspector",
      "args": ["${workspaceFolder}/protractor.conf.js"]
    }
  ]
}

任务。用于angular/cli的json

{
    "version": "2.0.0",
    "tasks": [
      {
        "identifier": "ng serve",
        "type": "npm",
        "script": "start",
        "problemMatcher": [],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      },
      {
        "identifier": "ng test",
        "type": "npm",
        "script": "test",
        "problemMatcher": [],
        "group": {
          "kind": "test",
          "isDefault": true
        }
      }
    ]
  }
  1. 安装Chrome调试器扩展
  2. 创建launch.json
  3. 用我的launch.json(见下文)
  4. 启动NG Live Development Server(ng service
  5. F5

启动。用于angular/cli的json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true,
      "userDataDir": "${workspaceFolder}/.vscode/chrome",
      "runtimeArgs": [
        "--disable-session-crashed-bubble"
      ]
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200",
      "port": 9222,
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true
    }
  ]
}

启动。用于angular/cli的json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Lunch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}/src/app",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///./~/*": "${workspaceFolder}/node_modules/*",
        "webpack:///./src/*": "${workspaceFolder}/src/*"
      },
      "userDataDir": "${workspaceFolder}/.vscode/chrome",
      "runtimeArgs": [
        "--disable-session-crashed-bubble"
      ]
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200",
      "port": 9222,
      "webRoot": "${workspaceFolder}/src/app",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///./~/*": "${workspaceFolder}/node_modules/*",
        "webpack:///./src/*": "${workspaceFolder}/src/*"
      }
    }
  ]
}

 类似资料:
  • 本指南将介绍如何使用 VSCode debugging 为您自己的 Electron 项目和 native Electron 代码库(Electron codebase)调试。 调试您的 Electron 应用 主进程 1. Open an Electron project in VSCode. $ git clone git@github.com:electron/electron-quick-

  • 使用的是 WNMP 的集成环境,服务启用后,如何用 vscode 对 php 代码进行断点调试?之前是使用 PHPStorm 进行断点调试的,想知道 vscode 能否实现类似的断点调试功能

  • 我需要在VsCode上调试我的反应原生应用程序,我是新的反应原生开发...:)我搜索并遵循不同的方法,但没有运气...:(首先,我遵循此方法https://medium.com/@Tunvirrahmantushs/react-nate-debug-with-vscode-in-imple-steps-bf39b6331e67并遵循此方法https://www.youtube.com/watch?

  • 问题内容: 我正在尝试使用VSCode调试在Docker上运行的PHP应用程序,但没有成功。 过去,我可以使用运行WAMP Server的VSCode轻松调试PHP应用程序,但是由于我开始使用Docker,所以无法调试。在网上搜索了几本教程,在StackOverflow上检查了一些线程,但是我仍然无法正常工作。 Dockerfile: xdebug.ini docker-compose.yml V

  • 按 ctrl + shift + d , 然后点击左上角的小齿轮配置,把下面代码复制进去。 在你的ts代码里面打上断点,点击绿色的小箭头开始调试即可。 这个非常有用,比你使用 console.log 调试快很多。 { // Use IntelliSense to learn about possible Node.js debug attributes. // Hover to v

  • 在最近的vscode版本中,python扩展现在使用debugpy作为默认的Python调试器,取代了旧的ptvsd。 我需要在一个软件程序中调试一个python脚本,该程序适用于python 3.2,而不适用于较新的版本。不幸的是,debugpy只适用于python 有没有办法在vscode python扩展中使用另一个调试器,或者选择使用哪个调试器?换句话说,是否可以调试python