【问题标题】:Angular not showing errors properly角度未正确显示错误
【发布时间】:2021-12-22 19:25:24
【问题描述】:

在我的 Angular 应用程序中,它没有正确显示错误。它总是在 main.js 中显示错误,而不是在我的其他 Angular 应用程序中显示的组件和行号。请查看此截图

这是我的 angular.json。好像缺少开发配置。

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": "fadcd178-4e22-400b-975d-788758cb58bf"
  },
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "route-app": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/route-app",
            "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": [
              "src/styles.scss",
              "node_modules/leaflet/dist/leaflet.css",
              "node_modules/leaflet.markercluster/dist/MarkerCluster.Default.css",
              "src/app/themes/styles/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "2mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "5kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "route-app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "route-app:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "route-app: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": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "../node_modules/ngx-simple-modal/styles/simple-modal.css",
              "src/styles.scss"
            ],
            "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": "route-app:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "route-app:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "route-app"
}

这是我的packages.json

{
  "name": "route-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    
  }
}

请帮忙。

谢谢

【问题讨论】:

    标签: angular typescript ionic-framework


    【解决方案1】:

    像这样添加开发配置。

            "build": {
                 :
              "configurations": {
                "production": {
                   :
                },
                "development": {
                  "buildOptimizer": false,
                  "optimization": false,
                  "vendorChunk": true,
                  "extractLicenses": false,
                  "sourceMap": true,
                  "namedChunks": true
                }
              }
            }
            "serve": {
                :
              "configurations": {
                "production": {
                  "browserTarget": "route-app:build:production"
                },
                "development": {
                  "browserTarget": "route-app:build:development"
                }
              }
    
    

    然后使用ng serve -c development 启动您的应用程序。

    【讨论】:

    • 您能详细说明一下吗?我使用 ng serve 在我的浏览器中提供应用程序
    • 出现错误 ng serve -c development 发生未处理的异常:工作区中未设置配置“开发”。有关详细信息,请参阅“/private/var/folders/rj/bq0ld78s20vbn0plbbwv029h0000gn/T/ng-rw0K0z/angular-errors.log”。
    • 对不起,我错过了更新配置文件。您必须将其添加到 serve 部分。我再次更新了我的答案。
    • 你能告诉我开发配置中哪个参数启用了错误日志吗?
    猜你喜欢
    • 2019-05-27
    • 1970-01-01
    • 1970-01-01
    • 2017-12-19
    • 2016-12-28
    • 2018-07-25
    • 1970-01-01
    • 2018-11-03
    • 1970-01-01
    相关资源
    最近更新 更多