X Tutup
The Wayback Machine - https://web.archive.org/web/20200628004206/https://github.com/angular/angular/issues/35663
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration 'production' is not set in the workspace when --prod and -c flags set #35663

Open
BillLudwig opened this issue Feb 24, 2020 · 13 comments

Comments

@BillLudwig
Copy link

@BillLudwig BillLudwig commented Feb 24, 2020

🐞 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.

@clydin
Copy link
Member

@clydin clydin commented Feb 24, 2020

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

@clydin clydin closed this Feb 24, 2020
@BillLudwig
Copy link
Author

@BillLudwig BillLudwig commented Feb 24, 2020

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

@clydin
Copy link
Member

@clydin clydin commented Feb 24, 2020

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.

@clydin clydin reopened this Feb 24, 2020
@ahsteele
Copy link

@ahsteele ahsteele commented Feb 25, 2020

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

Given @clydin's reply I would assume that a correct command would be ng build -c=release --aot

@alan-agius4 alan-agius4 transferred this issue from angular/angular-cli Feb 25, 2020
@ngbot ngbot bot modified the milestone: needsTriage Feb 25, 2020
@clydin
Copy link
Member

@clydin clydin commented Feb 25, 2020

@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"
                }
              ]
            }
@redevill
Copy link

@redevill redevill commented Mar 4, 2020

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

@Theinfinix500
Copy link

@Theinfinix500 Theinfinix500 commented Mar 6, 2020

@redevill same problem here cant build the library into production mode. Configuration 'production' is not set in the workspace.

@redevill
Copy link

@redevill redevill commented Mar 6, 2020

@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.

@karthikVj-pfizer
Copy link

@karthikVj-pfizer karthikVj-pfizer commented Mar 27, 2020

I have 3 different environments on my side and i have been building packets using the following command.
ng build --configuration=test app
ng build --configuration=stage app
ng build --configuration=prod app

with separate output folders and separate environment.ts files. How do i set it up now?

@Springrbua
Copy link

@Springrbua Springrbua commented Mar 30, 2020

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.

@redevill
Copy link

@redevill redevill commented Mar 30, 2020

A follow up from my previous comment - I published the library, and it appears to behave just fine. Using the "default" no flag supplied build option.

@ngbot ngbot bot modified the milestones: needsTriage, Backlog Apr 6, 2020
@kapunahelewong kapunahelewong added this to Committed - Selected for development in docs Apr 6, 2020
@ciekawy
Copy link

@ciekawy ciekawy commented Apr 8, 2020

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

angular/angular-cli#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
  }
@kapunahelewong
Copy link
Contributor

@kapunahelewong kapunahelewong commented May 27, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
docs
Committed - Selected for development
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
11 participants
You can’t perform that action at this time.
X Tutup