简体   繁体   English

Angular ng 服务导致:发生未处理的异常:未在工作区中设置配置“生产”

[英]Angular ng serve leads to: An unhandled exception occurred: Configuration 'production' is not set in the workspace

I try to serve an angular (9.1.12) application with ng serve --configuration=production local to test the application in production mode.我尝试使用ng serve --configuration=production local 为 angular (9.1.12) 应用程序提供服务,以在生产模式下测试应用程序。 I receive the error: Angular ng serve leads to An unhandled exception occurred: Configuration 'production' is not set in the workspace.我收到错误: Angular ng serve leads to An unhandled exception occurred: Configuration 'production' is not set in the workspace. Any ideas what the issue might be?任何想法可能是什么问题?

My angular.json我的 angular.json

"serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "port": 4300,            
        "browserTarget": "employee-platform:build"
   },
   "configurations": {
      "production": {
          "browserTarget": "employee-platform:build:production"
      }
   }
},

similar to the "serve" please check in the "build" object and check for "configuration" some thing like below,类似于“服务”,请检查“构建”object 并检查“配置”,如下所示,

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

where in the src/environments/environment.prod.ts file,在 src/environments/environment.prod.ts 文件中,

we have to set production to true我们必须将生产设置为真

export const environment = {
  production: true
};

It looks like you are missing a configuration section under build object:看起来您缺少build object 下的配置部分:

"build": {
      ...
   },
   "configurations": {
      "production": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ],
          ...
      }
   }
},
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发生未处理的异常:在工作空间中未设置配置'es5'。 ng在角度8中投放es5 - An unhandled exception occurred: Configuration 'es5' is not set in the workspace. ng serve in angular 8 for es5 发生未处理的异常:工作区中未设置配置“生产” - An unhandled exception occurred: Configuration 'production' is not set in the workspace 使用 ng serve 在 angular 中发生未处理的异常 - An unhandled exception occurred in angular using ng serve 发生未处理的异常:工作区中未设置配置“dev” - An unhandled exception occurred: Configuration 'dev' is not set in the workspace 发生未处理的异常:工作区中未设置配置“es” - An unhandled exception occurred: Configuration 'es' is not set in the workspace 运行 ng serve 发生未处理的异常 - Unhandled exception occurred running ng serve 工作区中未设置配置“生产” - Angular - Configuration 'production' is not set in the workspace - Angular angular ng serve 命令抛出错误:发生未处理的异常:项目不存在 - angular ng serve command throws error: An unhandled exception occurred: Project does not exist 发生未处理的异常:无法使用 ng serve 找到模块“@angular/compiler-cli” - An unhandled exception occurred: Cannot find module '@angular/compiler-cli' with ng serve Angular cli 显示错误“发生未处理的异常:没有项目支持‘测试’目标。” 运行 ng test 或 ng serve 命令时 - Angular cli showing error "An unhandled exception occurred: No projects support the 'test' target." when running ng test or ng serve command
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM