发生未处理的异常:工作区中未设置“dev”配置。

4

我开始发布我的Angular应用程序。但我无法修复这个错误。我在Azure中进行了部署。添加这看起来很容易。我认为问题在 angular.json 中。首先,我尝试更新package.json中的每个依赖项。

这个配置文件哪里出错了?

    {
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ODZ.Web": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "progress": false,
            "extractCss": false,
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css",
              "node_modules/@fortawesome/fontawesome-free/scss/fontawesome.scss",
              "node_modules/@fortawesome/fontawesome-free/scss/solid.scss",
              "node_modules/@fortawesome/fontawesome-free/scss/regular.scss",
              "node_modules/@fortawesome/fontawesome-free/scss/brands.scss",
              "node_modules/angular-bootstrap-md/assets/scss/bootstrap/bootstrap.scss",
              "node_modules/angular-bootstrap-md/assets/scss/mdb.scss",
              "node_modules/animate.css/animate.css",
              "src/styles.css"
            ],
            "scripts": [
              "node_modules/chart.js/dist/Chart.js",
              "node_modules/hammerjs/hammer.min.js"
            ]
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ODZ.Web:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "ODZ.Web:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ODZ.Web:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.css"
            ],
            "scripts": [],
            "assets": [
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist-server",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.server.json"
          }
        }
      }
    },
    "ODZ.Web-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "ODZ.Web:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          },
          "configurations": {
            "production": {
              "devServerTarget": "ODZ.Web:serve:production"
            }
          }
        }
      }
    }
  },
  "defaultProject": "ODZ.Web"
}

我尝试修复这个问题,但是当我执行npm build --prod时...我改变了项目中的所有依赖项,但没有帮助。如果有人正在修复这个错误,请帮忙!谢谢!


2
这个回答解决了你的问题吗?Angular - 配置未在工作区中设置 - SomeDeveloper
2个回答

1
在angular.json的"serve"中添加以下内容:"options": { "browserTarget": "gox-sistema:build" }

Quedaria algo asi:

"serve": {
  "builder": "@angular-devkit/build-angular:dev-server",
  "options": {
    "browserTarget": "nombreApp:build"
  },
  "configurations": {
    "production": {
      "browserTarget": "nombreApp:build:production"
    },
    "development": {
      "browserTarget": "nombreApp:build:development"
    }
  }
},


这对我有用,谢谢 :) - undefined

-1

当我运行以下构建命令时,遇到了类似的错误:

ng build --configuration=DEV --crossOrigin=anonymous 

在Jenkins中:
An unhandled exception occurred: Configuration 'DEV' is not set in the workspace.

在日志文件中:

Log filename: /tmp/ng-W1hy24/angular-errors.log 

[error] Error: Configuration 'DEV' is not set in the workspace.

我相信下面是导致angular.json文件出现问题的两个原因:

  1. JSON区分大小写,因此请使用相同的字段名称。
  2. angular.json缺少DEV配置。

检查是否缺少DEV配置,请添加类似以下内容的配置。

代码示例:

"DEV": {

             "fileReplacements": [

               {

                 "replace": "src/environments/environment.ts",

                 "with": "src/environments/environment.dev.ts"

               }

             ],

             "optimization": true,

             "outputHashing": "all",

             "sourceMap": false,

             "extractCss": true,

             "namedChunks": false,

             "aot": true,

             "extractLicenses": true,

             "vendorChunk": false,

             "buildOptimizer": true,

             "budgets": [

               {

                 "type": "initial",

                 "maximumWarning": "4mb",

                 "maximumError": "6mb"

               }

             ],

             "serviceWorker": true,

             "ngswConfigPath": "ngsw-config.json"

没有起作用,Angular 11 - Buchi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接