【问题标题】:Angular cli showing error "An unhandled exception occurred: No projects support the 'test' target." when running ng test or ng serve commandAngular cli 显示错误“发生未处理的异常:没有项目支持‘测试’目标。”运行 ng test 或 ng serve 命令时
【发布时间】:2020-07-08 01:24:27
【问题描述】:

我有一个基本的 Angular 应用程序,它运行良好。 ng serveng test 命令运行良好。最近作为针对不同环境的构建自动化的一部分,我引入了一些配置更改以允许根据环境加载不同的environment.ts 文件。为此,我编辑了 angular.json 文件。更改后,ng serveng test 命令无法执行。每当执行命令时,都会引发以下错误:

An unhandled exception occurred: No projects support the 'test' target.
See "C:\Users\account\AppData\Local\Temp\ng-BlbvgV\angular-errors.log" for further details.

修改后的angular.json为:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "applicationui": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "../applicationservice/src/main/resources/static",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"
            ],
            "scripts": [
              "node_modules/chart.js/dist/Chart.min.js",
              "node_modules/jquery/dist/jquery.min.js",
              "node_modules/bootstrap/dist/js/bootstrap.min.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            },
            "qa": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.qa.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            },
            "dev-qa": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev-qa.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            },
            "dev-prod": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev-prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            },
            "dev": {
              "optimization": false,
              "outputHashing": "all",
              "sourceMap": true,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": false,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          },
          "serve": {
            "builder": "@angular-devkit/build-angular:dev-server",
            "options": {
              "browserTarget": "applicationui:build"
            },
            "configurations": {
              "production": {
                "browserTarget": "applicationui:build:production"
              },
              "qa": {
                "browserTarget": "applicationui:build:qa"
              },
              "dev-qa": {
                "browserTarget": "applicationui:build:dev-qa"
              },
              "dev-prod": {
                "browserTarget": "applicationui:build:dev-prod"
              },
              "dev": {
                "browserTarget": "applicationui:build:dev"
              }
            }
          },
          "extract-i18n": {
            "builder": "@angular-devkit/build-angular:extract-i18n",
            "options": {
              "browserTarget": "applicationui:build"
            }
          },
          "test": {
            "builder": "@angular-devkit/build-angular:karma",
            "options": {
              "codeCoverage": true,
              "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": "applicationui:serve"
            },
            "configurations": {
              "production": {
                "devServerTarget": "applicationui:serve:production"
              }
            }
          }
        }
      }
    }
  },
  "defaultProject": "applicationui"
}

【问题讨论】:

    标签: angular build angular8 angular-test angular-cli-v8


    【解决方案1】:

    对我来说是由于 microsoft windows 的 ExecutionPolicy 导致的错误。我读了this

    我也看到了我目前的政策:

    Get-ExecutionPolicy -List
    

    我运行此命令将其更改为无限制:

    Set-ExecutionPolicy Unrestricted
    

    现在的政策是这样的:

     Scope ExecutionPolicy
            ----- ---------------
    MachinePolicy       Undefined
       UserPolicy       Undefined
          Process       Undefined
      CurrentUser       Undefined
     LocalMachine    Unrestricted
    

    它运行良好。

    【讨论】:

      【解决方案2】:

      这里有同样的问题,但 angular.json 不是我的问题(同一台 PC,具有相同 angular.json 文件的并行项目工作正常)。

      我认为这是由于 package.json 而不是在运行 npm install 后有所不同

      【讨论】:

        【解决方案3】:

        我发现了问题,这是一个放错位置的 } 。我在configuration 之前关闭了“build”目标,这导致了问题。更正angular.json

        {
          "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
          "version": 1,
          "newProjectRoot": "projects",
          "projects": {
            "applicationui": {
              "projectType": "application",
              "schematics": {},
              "root": "",
              "sourceRoot": "src",
              "prefix": "app",
              "architect": {
                "build": {
                  "builder": "@angular-devkit/build-angular:browser",
                  "options": {
                    "outputPath": "../applicationservice/src/main/resources/static",
                    "index": "src/index.html",
                    "main": "src/main.ts",
                    "polyfills": "src/polyfills.ts",
                    "tsConfig": "tsconfig.app.json",
                    "aot": false,
                    "assets": [
                      "src/favicon.ico",
                      "src/assets"
                    ],
                    "styles": [
                      "src/styles.css",
                      "node_modules/bootstrap/dist/css/bootstrap.min.css"
                    ],
                    "scripts": [
                      "node_modules/chart.js/dist/Chart.min.js",
                      "node_modules/jquery/dist/jquery.min.js",
                      "node_modules/bootstrap/dist/js/bootstrap.min.js"
                    ]
                  },
                  "configurations": {
                    "production": {
                      "fileReplacements": [
                        {
                          "replace": "src/environments/environment.ts",
                          "with": "src/environments/environment.prod.ts"
                        }
                      ],
                      "optimization": true,
                      "outputHashing": "all",
                      "sourceMap": false,
                      "extractCss": true,
                      "namedChunks": false,
                      "aot": true,
                      "extractLicenses": true,
                      "vendorChunk": false,
                      "buildOptimizer": true,
                      "budgets": [
                        {
                          "type": "initial",
                          "maximumWarning": "2mb",
                          "maximumError": "5mb"
                        },
                        {
                          "type": "anyComponentStyle",
                          "maximumWarning": "6kb",
                          "maximumError": "10kb"
                        }
                      ]
                    },
                    "qa": {
                      "fileReplacements": [
                        {
                          "replace": "src/environments/environment.ts",
                          "with": "src/environments/environment.qa.ts"
                        }
                      ],
                      "optimization": true,
                      "outputHashing": "all",
                      "sourceMap": false,
                      "extractCss": true,
                      "namedChunks": false,
                      "aot": true,
                      "extractLicenses": true,
                      "vendorChunk": false,
                      "buildOptimizer": true,
                      "budgets": [
                        {
                          "type": "initial",
                          "maximumWarning": "2mb",
                          "maximumError": "5mb"
                        },
                        {
                          "type": "anyComponentStyle",
                          "maximumWarning": "6kb",
                          "maximumError": "10kb"
                        }
                      ]
                    },
                    "dev-qa": {
                      "fileReplacements": [
                        {
                          "replace": "src/environments/environment.ts",
                          "with": "src/environments/environment.dev-qa.ts"
                        }
                      ],
                      "optimization": true,
                      "outputHashing": "all",
                      "sourceMap": false,
                      "extractCss": true,
                      "namedChunks": false,
                      "aot": true,
                      "extractLicenses": true,
                      "vendorChunk": false,
                      "buildOptimizer": true,
                      "budgets": [
                        {
                          "type": "initial",
                          "maximumWarning": "2mb",
                          "maximumError": "5mb"
                        },
                        {
                          "type": "anyComponentStyle",
                          "maximumWarning": "6kb",
                          "maximumError": "10kb"
                        }
                      ]
                    },
                    "dev-prod": {
                      "fileReplacements": [
                        {
                          "replace": "src/environments/environment.ts",
                          "with": "src/environments/environment.dev-prod.ts"
                        }
                      ],
                      "optimization": true,
                      "outputHashing": "all",
                      "sourceMap": false,
                      "extractCss": true,
                      "namedChunks": false,
                      "aot": true,
                      "extractLicenses": true,
                      "vendorChunk": false,
                      "buildOptimizer": true,
                      "budgets": [
                        {
                          "type": "initial",
                          "maximumWarning": "2mb",
                          "maximumError": "5mb"
                        },
                        {
                          "type": "anyComponentStyle",
                          "maximumWarning": "6kb",
                          "maximumError": "10kb"
                        }
                      ]
                    },
                    "dev": {
                      "optimization": false,
                      "outputHashing": "all",
                      "sourceMap": true,
                      "extractCss": true,
                      "namedChunks": false,
                      "aot": true,
                      "extractLicenses": true,
                      "vendorChunk": false,
                      "buildOptimizer": false,
                      "budgets": [
                        {
                          "type": "initial",
                          "maximumWarning": "2mb",
                          "maximumError": "5mb"
                        },
                        {
                          "type": "anyComponentStyle",
                          "maximumWarning": "6kb",
                          "maximumError": "10kb"
                        }
                      ]
                    }
                  }},
                  "serve": {
                    "builder": "@angular-devkit/build-angular:dev-server",
                    "options": {
                      "browserTarget": "applicationui:build"
                    },
                    "configurations": {
                      "production": {
                        "browserTarget": "applicationui:build:production"
                      },
                      "qa": {
                        "browserTarget": "applicationui:build:qa"
                      },
                      "dev-qa": {
                        "browserTarget": "applicationui:build:dev-qa"
                      },
                      "dev-prod": {
                        "browserTarget": "applicationui:build:dev-prod"
                      },
                      "dev": {
                        "browserTarget": "applicationui:build:dev"
                      }
                    }
                  },
                  "extract-i18n": {
                    "builder": "@angular-devkit/build-angular:extract-i18n",
                    "options": {
                      "browserTarget": "applicationui:build"
                    }
                  },
                  "test": {
                    "builder": "@angular-devkit/build-angular:karma",
                    "options": {
                      "codeCoverage": true,
                      "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": "applicationui:serve"
                    },
                    "configurations": {
                      "production": {
                        "devServerTarget": "applicationui:serve:production"
                      }
                    }
                  }
                }
              }
            },
          "defaultProject": "applicationui"
        }
        

        【讨论】:

          猜你喜欢
          • 2019-12-26
          • 1970-01-01
          • 2022-07-20
          • 2017-03-07
          • 2018-12-30
          • 2021-09-04
          • 2019-07-02
          • 2020-12-29
          • 1970-01-01
          相关资源
          最近更新 更多