Angular - 工作区中未设置配置
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
完美运行
您收到的错误是因为您没有将其添加到服务浏览器目标配置中:
"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"
}
},
},
这对我有用。
我在 Angular 和 Angular Universal V 12.x 中遇到了同样的错误,Angular.json 文件中的以下代码修复了我的错误(替换 serve-ssr 部分使用以下代码):
"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"
}
}
}
我尝试使用我的特定配置为我的 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
完美运行
您收到的错误是因为您没有将其添加到服务浏览器目标配置中:
"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"
}
},
},
这对我有用。
我在 Angular 和 Angular Universal V 12.x 中遇到了同样的错误,Angular.json 文件中的以下代码修复了我的错误(替换 serve-ssr 部分使用以下代码):
"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"
}
}
}