首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >出现未处理的异常:未在工作区中设置配置'production‘

出现未处理的异常:未在工作区中设置配置'production‘
EN

Stack Overflow用户
提问于 2020-05-14 17:59:29
回答 1查看 10.5K关注 0票数 7

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

在进行本地化以准备产品构建之前,我通常会发出以下命令。

代码语言:javascript
复制
ng build --prod --base-href "/Windchill/com/qiwkCollaborator/"

本地化后,我在angular.json和package.json中做了一些更改。在进行这些更改之后,每当我给出任何命令来准备构建它时,它都会给我以下错误。

代码语言:javascript
复制
An unhandled exception occurred: Configuration 'production' is not set in the workspace.

Package.json文件的某些部分如下所示:

代码语言:javascript
复制
"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文件的某些部分如下所示。

代码语言:javascript
复制
"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"
            }
          }
        },

有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-14 18:06:05

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

您需要将构建脚本更改为

代码语言:javascript
复制
"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目标中

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61794486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档