Installing “Getting Started with Angular Signals” Code Lab Locally
I revisited Compass, my Angular practice project, in light of what I've recently learned about Angular standalone components & other things. And now I'll rewind back to Getting Started with Angular Signals code lab. I've gone through the primary exercise of Angular signals, but the app has many more lessons to teach me. The first one is: how do I fix a broken Angular build? Because while the code lab works fine on the recommended StackBlitz online environment, it failed to install locally on my development machine when I ran "npm install
"
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: qgnioqqrg.github@0.0.0
npm ERR! Found: @angular/compiler@15.2.9
npm ERR! node_modules/@angular/compiler
npm ERR! @angular/compiler@"^15.2.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @angular/compiler@"15.1.0-next.2" from @angular/compiler-cli@15.1.0-next.2
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"15.1.0-next.2" from the root project
Earlier, for the sake of doing the Angular signals code lab, I resorted to using error-free StackBlitz. Now I want to get it working locally. Checking the versions published to NPM for @angular/compiler
package, I see 15.1.0-next.2
listed. @angular/compiler-cli
also showed a 15.1.0-next.2
as a valid version. Their presence eliminated the "listing nonexisting version" as a candidate problem.
What's next? I thought it might be how @angular/compiler
has several different versions listed. Not just 15.1.0-next.2
that I checked, but also 15.2.9
and 15.2.2
. Why don't they match? Looking for the source of these version numbers, I looked through the repository and found they were listed in package.json
file. I see 15.1.0-next.2
was explicitly named for the three @angular/[...]
components under devDependencies
, while "^15.2.2
" is specified for all the @angular/[...]
components under dependencies
. That "^" prefix is apparently a "caret range" specifier, and 15.2.9 is the latest version that satisfies the caret range.
In order to make all @angular/[...]
component versions consistent, I replaced all three instances of "15.1.0-next.2
" with "^15.2.2
". That got me to the next error.
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: qgnioqqrg.github@0.0.0
npm ERR! Found: typescript@4.7.4
npm ERR! node_modules/typescript
npm ERR! dev typescript@"~4.7.2" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@">=4.8.2 <5.0" from @angular/compiler-cli@15.2.9
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"^15.2.2" from the root project
npm ERR! peer @angular/compiler-cli@"^15.0.0" from @angular-devkit/build-angular@15.2.8
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR! dev @angular-devkit/build-angular@"^15.2.2" from the root project
Updating to 15.2.9 meant TypeScript "~4.7.2
" is too old. Not fully understand what changed between those versions, I tried the lowest version listed as acceptable: 4.8.2. These version number changes were required to make them consistent with each other, and that is enough to bring me to the next error:
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: qgnioqqrg.github@0.0.0
npm ERR! Found: @angular/animations@16.0.3
npm ERR! node_modules/@angular/animations
npm ERR! peer @angular/animations@"^16.0.0 || ^17.0.0" from @angular/material@16.0.1
npm ERR! node_modules/@angular/material
npm ERR! @angular/material@"^15.2.2" from the root project
npm ERR! peerOptional @angular/animations@"16.0.3" from @angular/platform-browser@16.0.3
npm ERR! node_modules/@angular/platform-browser
npm ERR! peer @angular/platform-browser@"16.0.3" from @angular/forms@16.0.3
npm ERR! node_modules/@angular/forms
npm ERR! peer @angular/forms@"^16.0.0 || ^17.0.0" from @angular/material@16.0.1
npm ERR! node_modules/@angular/material
npm ERR! @angular/material@"^15.2.2" from the root project
npm ERR! 1 more (the root project)
npm ERR! peer @angular/platform-browser@"^16.0.0 || ^17.0.0" from @angular/material@16.0.1
npm ERR! node_modules/@angular/material
npm ERR! @angular/material@"^15.2.2" from the root project
npm ERR! 3 more (@angular/platform-browser-dynamic, @angular/router, the root project)
npm ERR! 1 more (the root project)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! @angular/animations@"^15.2.2" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: @angular/core@15.2.9
npm ERR! node_modules/@angular/core
npm ERR! peer @angular/core@"15.2.9" from @angular/animations@15.2.9
npm ERR! node_modules/@angular/animations
npm ERR! @angular/animations@"^15.2.2" from the root project
Since I had upgraded my Angular tools to v16 for Compass, I now have a problem with this project which specified an older version. Now I have to downgrade with the following steps:
- Uninstalling Angular v16 via "
npm uninstall -g @angular/cli
" - Flush v16 binaries from my project tree with "
rm -rf node_modules
" - Installing 15.2.2 with "
npm install -g @angular/cli@15.2.2
".
With these version numbers updated, I was able to run "npm install
" successfully to install remaining dependencies.
How did this work on StackBlitz when I had problems on my local machine? I hypothesize that StackBlitz handles their installation procedure differently than a local "npm install
". If they ignore the "devDependencies
" section, there wouldn't have been a conflict with "15.1.0-next.2
" modules. And if they ignored the caret range and used "15.2.2
" exactly instead moving up to 15.2.9, there wouldn't have been a TypeScript conflict either.
For now, I have solved my Node.js package management headaches and onwards to Angular headaches.
My code changes are made in my fork of the code lab repository in branch signals-get-started
.