Issue
This prior SO post was read prior to this question.
I was getting the error by installing @ngrx/store to a project being used for a PluralSight course.
Here is what I ran into upon install and decided 'Dammit, I'm going to understand what this means once and for all. Step 1: Google 'What does --legacy-peer-deps do' and obviously found the above matching article.
Very carefully read the above SO Post.
Forgive me not using the code block or block quote, for whatever reason these are not working so I put in blank lines instead.
C:\Training\NgrxFundamentals_2023\demo>npm install @ngrx/effects
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! While resolving: pluralsight-ngrx-fundamentals@0.0.0
npm ERR! Found: @angular/core@16.2.12
npm ERR! node_modules/@angular/core
npm ERR! @angular/core@"^16.0.0" from the root project
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/core@"^17.0.0" from @ngrx/effects@17.0.1
npm ERR! node_modules/@ngrx/effects
npm ERR! @ngrx/effects@"*" from the root project
If a dependency can't be resolved, as opposed to saying it's missing, that's throwing me.
At this point, read the answers by Chris Perry and Izzy several times. Finally ran:
npm install @ngrx/store --legacy-peer-deps
Then used Chris' code to find what the dependencies are for @ngrx/store. Did both of these out of sequence.
C:\Training\NgrxFundamentals_2023\demo>npm info @ngrx/effects peerDependencies
{ '@angular/core': '^17.0.0',
'@ngrx/store': '17.0.1',
rxjs: '^6.5.3 || ^7.5.0'
}
Then the lights came on -- here's part of dependencies from my package.json:
"dependencies": {
"@angular/animations": "^16.0.0",
"@angular/common": "^16.0.0",
"@angular/compiler": "^16.0.0",
"@angular/core": "^16.0.0",
"@angular/forms": "^16.0.0",
"@angular/platform-browser": "^16.0.0",
"@angular/platform-browser-dynamic": "^16.0.0",
"@angular/router": "^16.0.0",
"@ngrx/effects": "^17.0.1",
"@ngrx/store": "^17.0.1",
"@ngrx/store-devtools": "^17.0.1",
Isn't the simplest answer, at least in this case, that @ngrx/store latest version now expects angular core ^17.0.0? And that the --legacy-peer-deps is saying "Use an earlier core version anyway?"
Here's what I get from Chris:
One way of thinking of this flag is that it isn't doing something new; rather it's telling NPM not to do something new, since NPM v7 now installs peerDependencies by default. ... The --legacy-peer-deps flag was introduced with v7 as a way to bypass peerDependency auto-installation; it tells NPM to ignore peer deps and proceed with the installation anyway.
That is, if peer dependencies were being installed anyway, the error would not be there, right? Running --legacy-peer-deps worked.
Looking at both Izzy's and Chris' answers from the other post, I'm not really getting why this is working.
Also, since @ngrx/store is at version 17 and the lessons from the course are still at core 16, it appears @ngrx/store expects 17 but will run on 16.
So -- if this is the case, why flag the error and cause confusion?
The answers in the other link are very informative but a little hard to digest and resolve.
My goal here is to walk away with a clear understanding of --legacy-peer-deps, why it just did what it did and be able to teach others.
Thanks!
Solution
Seems you already dug in deep so you should have a good understanding of it from now, so maybe I'll try to summarize it ?
Each library you install has its own package.json file, with its dependencies. When you install a library, it also fetches all of those dependencies to make it work.
In the old days, NPM was accepting newer versions of those dependencies (called peer dependencies), hence the "legacy" name.
But nowadays, NPM has gotten stricter, and will only accept dependencies matching the semantic versioning provided.
This means that if a library is relying on angular ^16.0.0
, and you use angular other than 16, NPM won't accept it.
Answered By - MGX
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.