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