簡體   English   中英

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完美運行

您收到的錯誤是因為您沒有將其添加到您的服務 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"
            }
     }
}

Github

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM