[英]Angular - Configuration is not set in the workspace
我嘗試使用我的特定配置為我的 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.
我的 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
完美運行
您收到的錯誤是因為您沒有將其添加到您的服務 browserTarget 配置中:
"serve":{
"fr": {
"browserTarget": "custom-reports:build:fr"
},
}
在 Angular 11 中,您需要將browserTarget
屬性放在configurations
中(位於angular.json
文件中的serve
下):
"serve": {
"configurations": {
"fr": {
"browserTarget": "custom-reports:build:fr"
},
},
},
我也遇到了同樣的問題
An unhandled exception occurred: Configuration 'fr' is not set in the workspace.
See "/tmp/ng-nyZPjp/angular-errors.log" for further details.
即使我在服務和構建中設置了配置。
我的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"
}
},
},
我仍然有問題。
我通過更改配置的順序解決了它,它已經解決了。
我的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"
}
},
},
這對我有用。
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.