簡體   English   中英

發生未處理的異常:工作區中未設置配置“dev”

[英]An unhandled exception occurred: Configuration 'dev' is not set in the workspace

我開始發布我的 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 ......我改變了我項目中的每個依賴項,但沒有幫助。 如果有人正在修復此錯誤。 兄弟,求幫助! 謝謝!

當我運行構建命令時,我遇到了類似的錯誤,如下所示:

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

在詹金斯:

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"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM