VS Code 中的 Angular 调试 - 断点未绑定(bind)

标签 angular debugging ionic-framework visual-studio-code

我正在尝试在 VS Code 中调试我的 Ionic/Angular 项目,但是一旦我启动 Debug模式,我所有的断点都会变成灰色并变得未绑定(bind)。

这是我的 launch.json:

{
            "name": "Launch Chrome",
            "request": "launch",
            "type": "pwa-chrome",
            "url": "http://localhost:8100",
            "webRoot": "${workspaceFolder}"
}

我的 Angular 版本是 13.2.3,我的 Node 版本是 16.14.2。

我在 angular.json 文件中将 souceMap 设置为 true 并尝试调整设置,但没有任何效果。

感谢您的帮助!

最佳答案

VS code 团队提供了一套说明 here

基本上,您可以像这样配置/创建您的 launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "ng serve",
      "type": "chrome",
      "request": "launch",
      "preLaunchTask": "npm: start",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}",
      "sourceMapPathOverrides": {
        "webpack:/*": "${webRoot}/*",
        "/./*": "${webRoot}/*",
        "/src/*": "${webRoot}/*",
        "/*": "*",
        "/./~/*": "${webRoot}/node_modules/*"
      }
    },
    {
      "name": "ng test",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:9876/debug.html",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:/*": "${webRoot}/*",
        "/./*": "${webRoot}/*",
        "/src/*": "${webRoot}/*",
        "/*": "*",
        "/./~/*": "${webRoot}/node_modules/*"
      }
    },
    {
      "name": "ng e2e",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
      "args": ["${workspaceFolder}/e2e/protractor.conf.js"]
    }
  ]
}

tasks.json 对此:

{
  "version": "2.0.0",
  "tasks": [
    {
      "type": "npm",
      "script": "start",
      "isBackground": true,
      "presentation": {
        "focus": true,
        "panel": "dedicated"
      },
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": {
        "owner": "typescript",
        "source": "ts",
        "applyTo": "closedDocuments",
        "fileLocation": [
          "relative",
          "${cwd}"
        ],
        "pattern": "$tsc",
        "background": {
          "activeOnStart": true,
          "beginsPattern": {
            "regexp": "(.*?)"
          },
          "endsPattern": {
            "regexp": "Compiled |Failed to compile."
          }
        }
      }
    },
  ]
}

您只需按 F5 即可!

关于VS Code 中的 Angular 调试 - 断点未绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71718090/

相关文章:

javascript - 为什么这个函数会提示 URL 但没有提示字符串段?

android - Firebase api 初始化失败 Ionic Framework

javascript - 在 Angular2 中使用 guard 捕获重定向路由

node.js - 我应该选择什么来开始从 Visual Studio 开发 Angular 2 Web 应用程序?

angular - 如何在 Chrome 中调试 Angular2

ios - 无法使用 Safari 检查 iOS 11 设备

c++ - 将 HEX 转换为可打印的字符串/字符

ios - 我可以在 Windows 上使用 ionic 进行 IOS 开发吗?

android - 添加平台 android 时出错 : ShellCommandError: Non-zero exit from subprocess

javascript - 图像或 pdf 的文件输入验证