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)
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?
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 intsconfig.lib.conf
existing there and dedicated for building a library: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:If the
--prod
-flag is set, it simply concatsproduction
with the configurations set in--configuration
. However, the comment on the previousif
-statement says:So the comment says, that a
--configuration
will overwrite theconfiguration
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 therelease
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 theoptions
section and is used for both development and production builds now):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 executingng build -c=release -c=production --aot