Angular - 工作区中未设置配置

89

我试图使用我的特定配置为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 的使用完美无误。


类似问题:工作区中未设置配置“dev” - Aditya Y
4个回答

153

你遇到的错误是因为你没有将它添加到你的serve browserTarget配置中:

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

哈哈,我在那里拼错了单词。谢谢。 - minigeek
我的问题是由于某种原因,我的浏览器目标被设置为project:build:production,而不是我在angular.json中实际定义的"prod"。所以我将其更改为project:build:prod,然后它就可以工作了。我不知道发生了什么。 - FernandoG

25
在 Angular 11 中,您需要将 browserTarget 属性放置在 configurations 内(位于 angular.json 文件中的 serve 下):
"serve": {
    "configurations": {
        "fr": {
            "browserTarget": "custom-reports:build:fr"
        },
    },
},

9

我也遇到了相同的问题,

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

尽管我已经在“serve”和“build”中设置了配置,但是
我的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"
        }
    },
},

对我来说这很有效。


2
天啊,你是对的! - stilgar
@stilgar 天啊,你是对的!他是对的! - WernerCD

0

我在 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"
            }
     }
}

Github


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接