无法使用 Angular 13 在 VS Code 中命中断点

Muh*_*raz 5 debugging visual-studio-code angular vscode-debugger

下面是我的launch.js

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:4200",
            "webRoot": "${workspaceFolder}"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

在 中launch.js,我尝试将 webRoot 更改为"webRoot": "${workspaceFolder}/src",但没有产生影响。

我的应用程序已启动并正在运行ng serve,但是当我点击F5启动调试模式时,没有任何断点被命中,它们都是unbound/greyed out

以下是我angular.js的,以防有人需要。

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "angular-u-project-one": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/angular-u-project-one",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": false,
              "outputHashing": "all",
              "sourceMap": true,
              "namedChunks": true,
              "extractLicenses": false,
              "vendorChunk": true,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "angular-u-project-one:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "angular-u-project-one:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "angular-u-project-one:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "angular-u-project-one:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "angular-u-project-one:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "angular-u-project-one"
}
Run Code Online (Sandbox Code Playgroud)

下面是我的文件夹结构:

在此输入图像描述

还可以做些什么来使其发挥作用?

谢谢。

小智 0

我遇到了同样的问题,从 Angular 11 更新到 13,然后我找到了一些帮助,并在我的项目中执行了以下步骤:

1.- 编辑:angular.json 文件。

将以下行(sourceMap 和 optimization)添加到相应的部分或环境中,例如:

"configurations": {
    .......
    .......
    .......
   "dev" : {
    "sourceMap": true,
    "optimization": false,
    ..... // More code
   },
   "devlocal" : {
    "sourceMap": true,
    "optimization": false,
    ..... // More code
   }


}
Run Code Online (Sandbox Code Playgroud)

2.- 重新启动您的角度应用程序。3.- 将断点放入组件中。4.- 使用 Chrome 或 Visual Studio 代码调试您的应用程序。

就是这样!

这个对我有用。:)
问候!