angular: Configuration 'production' is not set in the workspace when --prod and -c flags set

šŸž Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, this command did not generate errors using Angular 8

Description

We have renamed the production build configuration to ā€œreleaseā€ in our angular.json file for internal consistency. Prior to upgrading to Angular 9 this worked without issue. Now when we run ng build -c=release --prod --aot we get the following error.

An unhandled exception occurred: Configuration 'production' is not set in the workspace.

While we can rename our release configuration to production we have a lot of projects and it breaks our internal naming convention. Since it was working prior to the upgrade we thought it was worth bringing up here before we refactor.

šŸ”¬ Minimal Reproduction

Create a new Angular project using the CLI. Rename the production build configuration to release (or anything else). Run ng build -c=release --prod --aot Get Error

šŸ”„ Exception or Error


An unhandled exception occurred: Configuration 'production' is not set in the workspace.

šŸŒ Your Environment


Angular CLI: 9.0.2
Node: 10.15.0
OS: win32 x64

Angular: 9.0.1
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.2
@angular-devkit/build-angular     0.900.2
@angular-devkit/build-optimizer   0.900.2
@angular-devkit/build-webpack     0.900.2
@angular-devkit/core              9.0.2
@angular-devkit/schematics        9.0.2
@angular/cli                      9.0.2
@ngtools/webpack                  9.0.2
@schematics/angular               9.0.2
@schematics/update                0.900.2
rxjs                              6.5.3
typescript                        3.7.5
webpack                           4.41.2

Anything else relevant? Shouldnā€™t be anything else.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Hey guys,

Anyone coming in for the first time creating lib, iā€™m sure will be reading this: https://angular.io/guide/creating-libraries

It specifically details the need not to use Ivy and use the --prod option as below screen shot. If you follow the instructions, you also get the ā€œConfiguration ā€˜productionā€™ is not setā€¦ā€ error. Please can someone advise me? Adjust the documentation?

image

in addition Iā€™ve just found --aot option is not available for libraries (as libraries are being build in AOT mode be fault?)

https://github.com/angular/angular-cli/issues/13328

OTOH what worked for me as per https://angular.io/guide/ivy there is dedicated tsconfig option to disable ivy - Iā€™ve put it in each of my libraries in tsconfig.lib.conf existing there and dedicated for building a library:

  "angularCompilerOptions": {
    "enableIvy": false
  }

Status: Docs team needs engineering input in order to correct/clarify documentation.

I just had a look at the code in angular cli architect-command.ts. As much as I understand, the issue comes from this code:

configuration =
          `${configuration ? `${configuration},` : ''}${commandOptions.configuration}`;

If the --prod-flag is set, it simply concats production with the configurations set in --configuration. However, the comment on the previous if-statement says:

The --prod flag will always be the first configuration, available to be overwritten by following configurations.

So the comment says, that a --configuration will overwrite the configuration set by --prod, while it actually only adds it. So itā€™s probably either a bug or the comment is outdated.

@Theinfinix500 - Well, the blind leading the blind - From what I can make out (meaning, that from what I have read and observation of behavior) the using the prod flag is no longer needed. I took the output from a build without the prod flag, and copied it to my node_modules. ā€œpretendingā€ that I did an npm install on the new library. Then referenced it in code. From a compile standpoint, this is working. Still need to see if the library functions correctly, and if the published version behaves the same. Hopefully someone with more knowledge will chip in.

I can see how that could cause confusion. Iā€™ll add a task to the backlog regarding a clarification to that section and Iā€™ll re-open this issue to track it here as well.

Thanks for the quick response. We were thrown off by the documentation on deployment that implied that the --prod flag actively enabled certain build steps.

https://angular.io/guide/deployment#production-optimizations

@ahsteele In regards to the --prod option, yes. If the goal is a production build then the options within the release configuration would also be relevant. The following is the set of options present in a production configuration for a new 9.0 project (AOT is enabled in the options section and is used for both development and production builds now):

            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }

Since 6.0, --prod has been an alias for --configuration=production and does not provide any other functionality.

ng build -c=release --prod --aot is the equivalent of executing ng build -c=release -c=production --aot