NX does not handle multiple configurations: nx run app:build --configuration=production,stage-env #22710
Replies: 38 comments
-
I've done some more testing and have found that it's if i do
it works
does not work. So it must be something to do with how we are passing along args. |
Beta Was this translation helpful? Give feedback.
-
Interesting, thanks for reporting this! 👍 |
Beta Was this translation helpful? Give feedback.
-
For me, none of cases works; returns:
and
strips the extra stage-env configuration from the --configuration I'm using these modules versions:
|
Beta Was this translation helpful? Give feedback.
-
Adding double quotes for me did the trick. |
Beta Was this translation helpful? Give feedback.
-
None of the following works in my case:
Each one reports the following error:
However, this command works fine:
Here is my environment:
|
Beta Was this translation helpful? Give feedback.
-
I would consider this more as a bug than a feature request. When migrating from the Angular CLI and running |
Beta Was this translation helpful? Give feedback.
-
Hi, just FYI, I recently upgraded NX 10 where -c config1,config2 was working and now it's broken on NX 11. Agree with @Splaktar, this is a bug, not a feature request as it was working before. Btw, this is the doco from the Angular CLI: https://angular.io/guide/workspace-config#alternate-build-configurations |
Beta Was this translation helpful? Give feedback.
-
@fbaba-nibtravel same here, just upgraded from NX 10 to NX 11 where
@FrozenPandaz Any chance you can rethink this and mark it as a bug? it's blocking me from upgrading. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, Sorry, I think there was some confusion with how the Angular CLI handles this behavior. It should be possible to support this behavior but as @vsavkin mentioned here, there are definitely some complexities here. I think we should be able to take this one step at a time though starting with the ability to execute Thank you for being patient and calmly explaining the confusion. |
Beta Was this translation helpful? Give feedback.
-
Hi all, So I attempted to implement the behavior and thought about the problem some more. We also have plans to improve the way workspaces are configured which is being considered here as well. While it was possible, I think it complicates the mental model because the defined configurations are not really intended to be used in isolation yet appear in the configuration. If I understand correctly, at a high level, people want to keep In my opinion, I do not think that combining multiple configurations is a good way to achieve this. Most use cases and examples that I see involve combining multiple configurations for a different use case from the combined configurations. For example, Rather, my initial thought is that extending configurations is a better way to achieve this. For example, to create a configuration for {
...,
"my-app": {
"options": { ... },
"configurations": {
"production": {
...
},
"staging": {
"__extends__": "production",
"baseUrl": "https://stage.example.com"
}
}
}
} I understand that if the behavior from Angular CLI isn't supported, With the ability to break up As a result, I don't think it's a good idea to merge #4889. For the time being, my recommendation would be to duplicate the configuration which I understand is not ideal. What do you all think about this? If this all sounds good, we will address this soon and get to a much better place for configuring workspaces. |
Beta Was this translation helpful? Give feedback.
-
Being able to extend sounds like a good plan. The drawback is that we no longer will be 100% compatible with angular cli. As long as it's well documented it shouldn't be a problem to migrate to it. |
Beta Was this translation helpful? Give feedback.
-
Hello @FrozenPandaz , While I think your response fits 100% to what @leon intended to achieve it misses entirely the problem described in a linked "duplicate". Please see my comment #4296 (comment) in #4296. There are two type of requirements around this features:
Those are two entirely different problems. To be honest, to me A) makes little sense. I'm a fan of being explicit as this has the lowest level of cognitive load to my brain and makes reading code easier but it has its fans I'm sure. But B) is almost an entirely different domain of problem. I absolutely need to mix my language configuration with different environments (development, staging, production) to serve or build the desired configuration. That feature of composing configurations always seemed really off to me. It's like the Angular CLI team decided for the wrong location to place the language configuration but when you look into the details of what you can do with "locale" configuration it makes a little bit more sense again. For example your are allowed to change any configuration per locale (because it is a configuration) and one example is to change the See this example:
A usual configuration rather looks like this:
To build all of your locales you can do this:
but if you want to use only one locale you can also use the configuration composition:
this also works for serve if yo u set the appropriate locales:
Here it falls apart.
If you chose to pass two locale-wise configurations to get two folders in dist: You have already seen the property Long story short, the configuration composition (that's how Angular calls this) has a real impact on teams relying on the native i18n handling. I'm very much aware that the Angular CLI team has here a lot of potential to improve the API surface but it works. It just works and that's why I would like to see Nx to support configuration composition. As said, yes, I can always pick Maybe you can evaluate your draft PR around providing this feature (https://github.com/nrwl/nx/pull/4889/files) again with those new information? Thank you for considering this change in Nx 🙏 |
Beta Was this translation helpful? Give feedback.
-
Absolutely agree with @georgiee Our use case is to have different brandings per customer - basically the same as for locales: we need these in all stages: dev, production We definitely want to stay angular compatible: i.e. use |
Beta Was this translation helpful? Give feedback.
-
Agree with the above here as well. My client isn't that concerned with (A) (mixing staging, production, test configs), they are very concerned with (B) (mixing locales and brands/customer builds). They are also not happy with the divergence from the Angular CLI functionality. They still consider it a bug for Nx CLI to not have a feature that the Angular CLI has, especially for migrations of projects that heavily use and depend upon this feature. The extending feature sounds good, but has it been discussed with the Angular CLI team? would they consider implementing something compatible with this? |
Beta Was this translation helpful? Give feedback.
-
We definitely want to stay angular compatible: i.e. use angular.json, too. |
Beta Was this translation helpful? Give feedback.
-
I found a bug & it seems related to this, so I created a separate issue |
Beta Was this translation helpful? Give feedback.
-
Threads like this get me wondering as to why "caching feature" is so involved and tangled in the core design. My personal take is one shouldn't design any solutions around "caching" concept. One should be able to come up with a basic design and add optional features like caching atop which consumers can switch on/off based on the specific usage requirements. Caching has always been an optional thing in software. Imagine we had built networks specifically based on the caching concept, I doubt we would have been able to use internet at all. In any case, awesome work nrwl team! The project is coming along very well and I'm stoked about your progress. |
Beta Was this translation helpful? Give feedback.
-
@raphael22
|
Beta Was this translation helpful? Give feedback.
-
It is still not working to make multipe configurations work in nx while this is working in angular. Any new information about this? PS: Workaround mentioned in #2839 (comment) is working so it seems the only solution |
Beta Was this translation helpful? Give feedback.
-
It's very counter-intuitive to apply all of these workarounds when migrating to Nx. Thank you for providing some examples, but I had to apply #2839 (comment) to make it work, and now I'm not using the @nrwl executor. Who knows when I will run into issues with this again. |
Beta Was this translation helpful? Give feedback.
-
As a more flexible workaround would it be realistic to have configuration files in javascript rather than json? Then we could easily write reusable blocks with infinite flexibility: const production = {
optimization: true,
extractLicenses: true,
inspect: false,
};
const alphaEnv = {
fileReplacements:[/*...*/];
};
const betaEnv = {
fileReplacements:[/*...*/];
};
module.exports = {
targets: {
build: {
/* ... */
configurations: {
"alpha-prod": {
...production,
...alphaEnv,
/* environment specific options */
},
"beta-prod": {
...production,
...betaEnv,
/* environment specific options */
}
}
}
}; |
Beta Was this translation helpful? Give feedback.
-
Hi, to add some more use cases. Currently I'm facing this issue and in our case we have configuration set per partner, device and environment. Currently we have 17 partner options, 4 device options and 2 environments. With the configuration composition we only need to define these 23 configuration and mix and match as we please, but with the workaround you suggest we would need 136 different configurations (a bit less as not all combinations are used but still a lot), that's insane! Plus another thing to mention is that imo decorating something, like the angular CLI, should add features but never remove existing features. As a workaround, if having multiple configuration is not possible with the nx cli it could just fall back and use the default ng cli for that. |
Beta Was this translation helpful? Give feedback.
-
I don't understand. How did it work before then? It was clearly there in <Nx 11. Something changed in nx 11 that broke this behavior... |
Beta Was this translation helpful? Give feedback.
-
When you set the I opened an issue that was considered as a duplicate but I'm explaining my case here : #17275 Have a great day! |
Beta Was this translation helpful? Give feedback.
-
There should be a central place to set project configuration for all projects, in |
Beta Was this translation helpful? Give feedback.
-
In my case I have a |
Beta Was this translation helpful? Give feedback.
-
I want to distinguish dev/prod builds and dev/prod envs. For example, if a bug occurs in production, I find it easier to run the app in production env (i.e. connect to production servers) to debug the problem from my local computer, BUT use a dev build, so I don't have to fight with code minification and source maps. What I do now is a custom executor that merges a bunch of |
Beta Was this translation helpful? Give feedback.
-
I am confused, it's a simple thing while at the same time pretty common and requested, why did is not getting any priority? It's been like 3 years now.. If you don't want to implement config merging then simply add support for |
Beta Was this translation helpful? Give feedback.
-
If this is still not officially supported, I think the least of the efforts for the dev team could be to add some kind of notification or an error message that this is the case. Especially since people may expect the command to mirror Angular CLI where this is supported. |
Beta Was this translation helpful? Give feedback.
-
Interested on this one. There should be a way to mimic the same feature in Angular. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Expected Behavior
When running commands using
nx
, they should behave the same asng
This works
ng run app:build --configuration=production,stage-env
this does not
nx run app:build --configuration=production,stage-env
Current Behavior
It seems that nx is stripping my extra
stage-env
configurations from the--configuration
Failure Information (for bugs)
I think it has to do with that in earlier version of the angular cli, multiple configurations where not supported, they where added here in November 2019
angular/angular-cli#15819
The problem nx has, is that it only supports one config.
nx/packages/tao/src/commands/run.ts
Line 46 in 115a1ab
nx/packages/tao/src/commands/run.ts
Lines 120 to 138 in 115a1ab
Solution
Change the implementation so that we are not limited to one config.
Beta Was this translation helpful? Give feedback.
All reactions