Title: feat(schematics): warn during ng add when firebase is installed at more than one version by armando-navarro · Pull Request #3760 · angular/angularfire · GitHub
Open Graph Title: feat(schematics): warn during ng add when firebase is installed at more than one version by armando-navarro · Pull Request #3760 · angular/angularfire
X Title: feat(schematics): warn during ng add when firebase is installed at more than one version by armando-navarro · Pull Request #3760 · angular/angularfire
Description: Fixes #3754 Refs #3684 Refs #3681 Refs #3682 What this does ng add @angular/fire now asks the project's own package manager which versions of firebase are installed, and says one of three things: more than one version was found, the check could not be completed, or nothing at all. It runs after the install task and before the feature prompt, so node_modules is on disk to be asked about and the answer appears whatever the user then selects. Why Two copies of the Firebase SDK produce two separate module instances, and objects made by one are rejected by the other. The symptoms name the user's own code, so the cause is not guessable from the error: Expected type '_Query', but it was: a custom _Collection object Type does not match the expected instance #3684, #3681 and #3682 are all this, and all open. In each case the diagnosis came down to one command a maintainer had to tell the reporter to run, npm ls firebase. This runs it for them. What a user sees Real ng add output, from a fresh Angular 21 app with firebase@12.18.0 at the root and firebase@11.10.0 under a local dependency: ✔ Packages installed successfully. ⚠️ Your workspace has more than one version of firebase installed. firebase: 2 distinct versions, reached by 4 dependent packages (according to npm) 12.18.0 via @angular/fire 12.18.0 via @angular/fire > rxfire 12.18.0 via the workspace root 11.10.0 via vendor-lib Two copies of the firebase SDK loaded by one app become two separate module instances, and they reject each other's objects at runtime with errors that name your own code rather than the duplication. Run npm ls firebase --all for the full tree. ? What features would you like to setup? The via lines are the part worth having: they name the dependency that pulled the second copy in, which is the fact a user needs in order to act. On the same app without the duplicate, ng add prints nothing between the install and the prompt. The rule about silence Printing nothing is itself a message: a user who reads nothing concludes the install was inspected and is fine. So every path that cannot reach an answer says so instead of staying quiet. A missing package manager, a lockfile written by a newer version, a manager that exits without printing, a project declaring bun, output in an unrecognized shape: each produces a second kind of warning that names what stopped the check. How it works Detect the manager from what the project declares (packageManager in package.json, cli.packageManager in angular.json), then from its lockfile. Both yarns share yarn.lock, so the lockfile's own first lines decide which (# yarn lockfile v1 for yarn 1.x, a __metadata: block for yarn 2+), with a yarn --version probe as the fallback when no lockfile is readable. Run that manager's own query: npm ls, pnpm -r ls, yarn why, yarn list. Read the four output formats into one shape, one file per manager. Hand the result to setup/duplicateWarning.ts, which is the only place that decides what to say. Commands run through cross-spawn with an argument array and no shell: true. Known limit In a monorepo the question is answered for the whole workspace while ng add was pointed at one project inside it. A project that resolves exactly one version of firebase can therefore be warned about a sibling's version that it does not depend on and cannot load. This is not fixed here. Scoping the answer is per-manager work: npm scopes if the command runs in the project's own directory, pnpm scopes if -r is dropped as well, and neither yarn scopes by directory at all. The message is worded so it is not false in that case (it explains what two copies loaded by one app do, rather than asserting a conflict has happened) and the via lines name which project each version came through. Tests 314 unit specs. Parsing is tested against output captured verbatim from real npm, pnpm, yarn 2+ and yarn 1.x installs, because invented fixtures would test a shape I imagined rather than the one each tool emits. One spec launches npm for real, since starting a package manager is the part captured output cannot cover and the part that fails first on Windows. Separately, and not part of CI: an acceptance list run against 16 real installed projects covering all four managers, workspaces, overrides and resolutions, locally linked packages, yarn 2+ virtual locators, and a yarn 1.x project with yarn 2+ on the PATH. Not included Scoping the answer to one project in a monorepo, described above. Any check outside ng add. This does not run at build time or as a lint rule.
Open Graph Description: Fixes #3754 Refs #3684 Refs #3681 Refs #3682 What this does ng add @angular/fire now asks the project's own package manager which versions of firebase are installed, and says one of three thing...
X Description: Fixes #3754 Refs #3684 Refs #3681 Refs #3682 What this does ng add @angular/fire now asks the project's own package manager which versions of firebase are installed, and says one of three t...
Opengraph URL: https://github.com/angular/angularfire/pull/3760
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:9db2738c-2d52-d227-7a31-9d8190d04c84 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 970E:2742B0:947416:BC0513:6B0362D4 |
| html-safe-nonce | 7a72882787a783ff31ac3df6490d0e0f04d174c69d6f39e6dc1661375f77bca1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzBFOjI3NDJCMDo5NDc0MTY6QkMwNTEzOjZCMDM2MkQ0IiwidmlzaXRvcl9pZCI6IjU5NDk2ODgwMDc4OTU1MDc2NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d6e0547a50eba2c3a37eed16faf820bb0ed275ea951b76306895a87873e44c7f |
| hovercard-subject-tag | pull_request:4409464426 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/angular/angularfire/pull/3760/files |
| twitter:image | https://avatars.githubusercontent.com/u/13904589?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/13904589?s=400&v=4 |
| og:image:alt | Fixes #3754 Refs #3684 Refs #3681 Refs #3682 What this does ng add @angular/fire now asks the project's own package manager which versions of firebase are installed, and says one of three thing... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/angular/angularfire git https://github.com/angular/angularfire.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 49453413 |
| octolytics-dimension-repository_nwo | angular/angularfire |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49453413 |
| octolytics-dimension-repository_network_root_nwo | angular/angularfire |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | no-cache |
Viewport: width=device-width