简体   繁体   English

Angular - 工作区中未设置配置

[英]Angular - Configuration is not set in the workspace

I try to serve my Angular app with my specific configuration but Angular does not recognize it:我尝试使用我的特定配置为我的 Angular 应用程序提供服务,但 Angular 无法识别它:

$ ng serve --configuration=fr
An unhandled exception occurred: Configuration 'fr' is not set in the workspace.
See "/tmp/ng-nyZPjp/angular-errors.log" for further details.

My angular.json:我的 angular.json:

"configurations": {
  "fr": {
    "aot": true,
    "outputPath": "dist/fr/",
    "i18nFile": "src/i18n/messages.fr.xlf",
    "i18nFormat": "xlf",
    "i18nLocale": "fr",
    "i18nMissingTranslation": "error",
    "baseHref": "/fr/"
  },
  "en": { 
    "aot": true,
    "outputPath": "dist/en/",
    "i18nFile": "src/i18n/messages.en.xlf",
    "i18nFormat": "xlf",
    "i18nLocale": "en",
    "i18nMissingTranslation": "error",
    "baseHref": "/en/"
  },
    ...

ng serve --configuration=en works perfectly ng serve --configuration=en完美运行

The error you are getting is because you didn't add it to your serve browserTarget configuration:您收到的错误是因为您没有将其添加到您的服务 browserTarget 配置中:

"serve":{
   "fr": {
            "browserTarget": "custom-reports:build:fr"
         },
 }

In Angular 11 you need to place the browserTarget property inside configurations (which is under serve in angular.json file):在 Angular 11 中,您需要将browserTarget属性放在configurations中(位于angular.json文件中的serve下):

"serve": {
    "configurations": {
        "fr": {
            "browserTarget": "custom-reports:build:fr"
        },
    },
},

I also faced the same issue,我也遇到了同样的问题

An unhandled exception occurred: Configuration 'fr' is not set in the workspace.
See "/tmp/ng-nyZPjp/angular-errors.log" for further details.

even though I had the configurations setup in serve and build.即使我在服务和构建中设置了配置。

My angular.json file was like,我的angular.json文件就像,

"configurations": {
  "fr": {
    "aot": true,
    "outputPath": "dist/fr/",
    "i18nFile": "src/i18n/messages.fr.xlf",
    "i18nFormat": "xlf",
    "i18nLocale": "fr",
    "i18nMissingTranslation": "error",
    "baseHref": "/fr/"
  },
  "en": { 
    "aot": true,
    "outputPath": "dist/en/",
    "i18nFile": "src/i18n/messages.en.xlf",
    "i18nFormat": "xlf",
    "i18nLocale": "en",
    "i18nMissingTranslation": "error",
    "baseHref": "/en/"
  },
  .
  .
  .
  .
  .
  .
  .
  .
  "serve": {
    "configurations": {
        "en": {
            "browserTarget": "custom-reports:build:en"
        },
        "fr": {
            "browserTarget": "custom-reports:build:fr"
        }
    },
},

and I still got issue.我仍然有问题。

I solved it by changing the order of the configuration and it was solved.我通过更改配置的顺序解决了它,它已经解决了。

my angular.json after change我的angular.json更改后

"configurations": {
  "en": { 
    "aot": true,
    "outputPath": "dist/en/",
    "i18nFile": "src/i18n/messages.en.xlf",
    "i18nFormat": "xlf",
    "i18nLocale": "en",
    "i18nMissingTranslation": "error",
    "baseHref": "/en/"
  },
  "fr": {
    "aot": true,
    "outputPath": "dist/fr/",
    "i18nFile": "src/i18n/messages.fr.xlf",
    "i18nFormat": "xlf",
    "i18nLocale": "fr",
    "i18nMissingTranslation": "error",
    "baseHref": "/fr/"
  },
  .
  .
  .
  .
  .
  .
  .
  .
  "serve": {
    "configurations": {
        "en": {
            "browserTarget": "custom-reports:build:en"
        },
        "fr": {
            "browserTarget": "custom-reports:build:fr"
        }
    },
},

and this worked for me.这对我有用。

I had the same error in the Angular with Angular Universal V 12.x and following codes in the Angular.json file fix my error(replace serve-ssr section with the following codes): I had the same error in the Angular with Angular Universal V 12.x and following codes in the Angular.json file fix my error(replace serve-ssr section with the following codes):

"serve-ssr": {
    "builder": "@nguniversal/builders:ssr-dev-server",
    "options": {
            "browserTarget": "yourAppName:build",
            "serverTarget": "yourAppName:server"
     },
     "configurations": {
            "production": {
                 "browserTarget": "yourAppName:build:production",
                 "serverTarget": "yourAppName:server:production"
            }
     }
}

Github Github

暂无
暂无

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

相关问题 Angular 配置未设置到工作区 - Angular configuration not set to the workspace 配置“开发”未在工作区中设置 Angular - Configuration 'development' is not set in the workspace Angular 工作区中未设置配置“生产” - Angular - Configuration 'production' is not set in the workspace - Angular Angular 12 通用配置“开发”未在工作区中设置 - Angular 12 Universal Configuration 'development' is not set in the workspace Angular ng 服务导致:发生未处理的异常:未在工作区中设置配置“生产” - Angular ng serve leads to: An unhandled exception occurred: Configuration 'production' is not set in the workspace 发生未处理的异常:在工作空间中未设置配置'es5'。 ng在角度8中投放es5 - An unhandled exception occurred: Configuration 'es5' is not set in the workspace. ng serve in angular 8 for es5 发生未处理的异常:工作区中未设置配置“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 发生未处理的异常:工作区中未设置配置“生产” - An unhandled exception occurred: Configuration 'production' is not set in the workspace 如何在 Angular 工作区配置上用属性 fileReplacements 替换文件? - How can I replace file with property fileReplacements on Angular workspace configuration?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM