angular - 发生未处理的异常 : Configuration 'production' is not set in the workspace

标签 angular angular-cli angular8 dev-to-production

嗨,在 Angular 8 中创建了一个项目。
最初它只支持一种默认语言(US-EN)。然后我应用了本地化。

在准备生产构建的本地化之前,我曾经给出以下命令。

ng build --prod --base-href "/Windchill/com/qiwkCollaborator/"

本地化后,我在 angular.json 和 package.json 中做了一些更改。在进行这些更改后,每当我发出任何准备构建它的命令时,都会出现以下错误。
An unhandled exception occurred: Configuration 'production' is not set in the workspace.

Package.json 文件的某些部分如下:
"name": "qwik-collaborator",
  "version": "1.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build-locale:en": "ng build --prod --i18n-locale en --i18n-format xlf --i18n-file src/translate/messages.en.xlf --output-path=dist/en --baseHref /en/",
    "build-locale:fr": "ng build --prod --i18n-locale fr --i18n-format xlf --i18n-file src/translate/messages.fr.xlf --output-path=dist/fr --baseHref /fr/"

Angular.json 文件的某些部分如下。
"build": {

          "configurations": {
            "fr": {
            "aot": true,
            "outputPath": "dist/qwikCollaborator/fr/",
            "i18nFile": "src/translate/messages.fr.xlf",      
            "i18nFormat": "xlf",      
            "i18nLocale": "fr",      
            "i18nMissingTranslation": "error"    
             },
             "en": {
            "aot": true,
            "outputPath": "dist/qwikCollaborator/en/",
            "i18nFile": "src/translate/messages.en.xlf",      
            "i18nFormat": "xlf",      
            "i18nLocale": "en",      
            "i18nMissingTranslation": "error"    
             }  
           },
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/qwikCollaborator",
            "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.scss",
              "src/assets/css/custom-mobile.css",
              "src/assets/css/custom.css"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.min.js",
              "src/assets/js/qwikCollaborator.js"
            ]
          },
          "configurations": {
          "es5": {
        "tsConfig": "./tsconfig.es5.json"
      },
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
.......


"serve": {
           "configurations": {
            "fr": {
            "browserTarget": "qwikCollaborator:build:fr" 
            },
            "en": {
            "browserTarget": "qwikCollaborator:build:en" 
            } ,
            },
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "qwikCollaborator:build"
          },

          "configurations": {
          "es5": {
        "browserTarget": "qwikCollaborator:build:es5"
      },
            "production": {
              "browserTarget": "qwikCollaborator:build:es5"
            }
          }
        },

谁能帮我这个?

最佳答案

您正在使用 --prod 构建,这意味着使用 production配置,您显然已删除

您需要将构建脚本更改为

"build-locale:en": "ng build -c en --output-path=dist/en --baseHref /en/",
"build-locale:fr": "ng build -c fr --output-path=dist/fr --baseHref /fr/"

angular.json 中指定的选项(如文件 i18n 文件格式和位置)不需要在构建命令中再次指定

如果您想使用 ng build --prod 构建和以前一样,您只需要添加 production配置回build目标

关于angular - 发生未处理的异常 : Configuration 'production' is not set in the workspace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61794486/

相关文章:

angular - canActivate 文档示例 - 一般理解

spring-boot - 获取(Set-Cookie)的值存入浏览器angular 8

angular - 我应该如何在 Angular 8 中为 @ViewChild 使用新的静态选项?

angular - 如何更改可观察对象的属性。 Angular 2/行为主题

Javascript Angular在数据目标中插入变量作为id

javascript - 语法错误 : Unexpected token C in JSON at position 0 - Ionic 2 Http GET request

Angular 2 在带有 Angular 路由器的 NPM 模块中延迟加载 NgModule

angular - 在 Angular 6.x 库编译期间删除 console.log

angular-cli - 如何在启用生产build设置和 AOT 的情况下运行 angular cli ng 测试

lazy-loading - 使用 webpack 4 的 Angular 8 延迟加载中未显示 chunkName