【问题标题】:Unable to hit breakpoint in VS Code with Angular 13无法使用 Angular 13 在 VS Code 中命中断点
【发布时间】:2021-12-30 20:21:24
【问题描述】:

下面是我的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}"
        }
    ]
}

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"
}

下面是我的文件夹结构:

还有什么可以让它发挥作用?

谢谢。

【问题讨论】:

    标签: angular debugging visual-studio-code vscode-debugger


    【解决方案1】:

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

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

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

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

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

    就是这样!!!

    它适用于我。 :)
    问候!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-15
      • 2018-10-16
      • 1970-01-01
      • 2022-01-16
      • 2018-08-11
      • 2022-12-23
      • 2021-10-15
      相关资源
      最近更新 更多