I can't seem to find the answer to this question, I've even asked it on gitter.
I want to know what the relationship is between the local version of the angular CLI and the local version of the angular cli?
Why do they have to be kept in sync?
What happens if you have multiple angular cli apps at different versions of the cli? Do they all need to be kept in lock step versionwise?
Any knowledge you could shed on this or point me somewhere that does would be really helpful.
Thanks!!!
... Ed
Hi Ed, I'd suggest you asking this on StackOverflow as here's more used for bug reporting.
But according to my understanding local "devDependencies" installation is just to isolate your local @angular/cli version from the global one. For example following a ng new you can use global cli by directly calling "ng" or use the local one with ./node_modules/\@angular/cli/bin/ng If there's a code breaking gap between two, your global ng command would fail but local would work. I had this issue while moving from angular-cli to @angular/cli.
As @demirk4n mentioned, this is probably best served for StackOverflow. As a brief overview though, running ng ... commands from within your project directory will use whatever version of the CLI you have installed globally. However, if you add scripts to your package.json referencing the CLI (eg. the existing start script that runs ng serve), and run npm start, npm run ..., etc., that will use whatever local version you have installed and that is specified in the devDependencies of your package.json.
I recommend using the second strategy I mentioned of referencing the ng ... commands in scripts in your package.json because it ensures that anyone running your project will always be using the same version of the CLI, leading to more consistent builds and overall development experience.
Of course, as you mentioned, some commands must be run globally, like ng new or ng g ..., so you will always have to use whatever global version you have installed for those commands. I try to keep my local version of the CLI as close to latest as possible, though it's always important to consider breaking changes, new features, etc. and determine on a case-by-case (or version-by-version) basis whether taking the latest update is beneficial to your project or not. Hope this helps!
An additional example for clarification - I have the following scripts in my package.json:
"build:dev": "ng build",
"build:prod": "ng build -prod -aot",
When I, or anyone else on my team needs to build the project we run npm run build:dev or npm run build:prod rather than running ng build or ng build -prod -aot directly. This guarantees us consistent builds of the project from anyone's machine (with the exception of inescapable OS-specific issues), regardless of which global version of the CLI that person has installed. It would be very difficult to achieve this consistency without using the local version of the CLI because it would mean maintaining consistent global versions across multiple machines.
Thanks @demirk4n and @phillipcurl for your responses. I will pose the question on Stack Overflow as well.
I'm actually surprised that it uses the global cli rather than the local cli. I was hoping that it would be more like grunt where it would use the local. This makes me wonder how we can deal with projects that use different versions of the cli. I would think that would cause an issue. If we have an older project and much newer projects in production, I would hate to have to upgrade an older project for a quick fix, that would probably be more change than what our QA group would want.
Maybe this will be dealt with when the cli comes out of beta and is officially released.
In any case, thanks so much for your comments!!!
The global version will actually delegate to the local project version if found.
This means you can have multiple projects with varying versions of the CLI, if needed.
I think this delegation (or version check) functionality is provided with the latest beta. I get the following when my global and local cli versions are different which wasn't the case before.
Your global Angular CLI version (1.0.0-beta.32.3) is greater than your local
version (1.0.0-beta.31). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false".
The warning is new but the delegation has been there since before the webpack conversion.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
An additional example for clarification - I have the following scripts in my package.json:
When I, or anyone else on my team needs to build the project we run
npm run build:devornpm run build:prodrather than runningng buildorng build -prod -aotdirectly. This guarantees us consistent builds of the project from anyone's machine (with the exception of inescapable OS-specific issues), regardless of which global version of the CLI that person has installed. It would be very difficult to achieve this consistency without using the local version of the CLI because it would mean maintaining consistent global versions across multiple machines.