Skip to content

fix(schematics): align the workspace firebase dependency with the supported range#3722

Open
armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:a16-firebase-version-alignment
Open

fix(schematics): align the workspace firebase dependency with the supported range#3722
armando-navarro wants to merge 1 commit into
angular:mainfrom
armando-navarro:a16-firebase-version-alignment

Conversation

@armando-navarro

@armando-navarro armando-navarro commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Checklist

Description

Upgrading an app to @angular/fire 21 while its own package.json still requests firebase@11 produces an install with two copies of the firebase SDK: npm keeps 11 at the root and nests 12 under @angular/fire. No install-time error fires, and the two copies reject each other's objects at runtime. #3684, #3681, and #3682 are all this one failure (analysis and reproductions in those threads).

This PR makes the schematics keep the workspace's firebase entry aligned with the range the library requires:

  • a shared alignFirebaseVersion helper and firebaseVersionRange constant in src/schematics/common.ts;
  • ng add writes the entry when missing and realigns an incompatible one before its install task runs;
  • a new migration-v21 runs the same alignment during ng update @angular/fire, scheduling an install only when it changed something (the CLI re-runs the migration on rc-to-stable updates, so the no-op path matters).

Behavior details:

  • A range is rewritten only when it is not entirely inside ^12.4.0 (semver.subset); intersects would keep ranges like ^12.0.0 or >=11 that a stale lockfile still resolves below the required floor.
  • Non-semver specifiers (dist-tags, workspace:, file:, git URLs) are never rewritten; the user gets a warning explaining the risk instead.
  • firebaseVersionRange intentionally duplicates dependencies.firebase from src/package.json instead of being injected at build time: the build's version-injection machinery (versions.json) is under discussion in The ANGULARFIRE2_VERSION build placeholder ships unreplaced in the library, and versions.json never reaches the compiled schematics #3715, so the constant is the minimal bridge that machinery can later supersede. A spec reads src/package.json and fails the suite if the two values ever drift.

Verified end-to-end against a packed build. A fixture app with firebase@11.8.0 installed next to this package (the exact broken tree from the linked issues), then ng update @angular/fire --migrate-only --from=20.0.1:

❯ Align the workspace's firebase dependency with the range @angular/fire 21 requires,
  so the install cannot contain two copies of the firebase SDK.
    Updated the firebase version in your package.json from ^11.8.0 to ^12.4.0, the range
    @angular/fire requires; a workspace range outside it can leave the install with a
    second copy of the firebase SDK, which fails at runtime.
UPDATE package.json (400 bytes)
✔ Packages installed successfully.

npm ls firebase afterwards shows a single firebase@12.16.0, and a second run reports "Migration completed (No changes made)".

…ported range

Upgrading an app whose own package.json still pins firebase 11 leaves
npm building a tree with two firebase SDK copies: the stale one at the
root (rxfire binds to it) and a second nested under @angular/fire. No
install-time error fires, and the two copies reject each other's
objects at runtime; angular#3684, angular#3681, and angular#3682 are all this one failure.

A shared alignFirebaseVersion helper now runs in both places the
schematics touch a project: ng add writes or realigns the firebase
entry before its install task, and a new migration-v21 does the same
during ng update, gated so a re-run on rc-to-stable updates is a no-op
(the CLI strips the prerelease from the migration range's upper bound,
so the migration re-executes on those transitions). Ranges not
entirely inside ^12.4.0 are rewritten via semver.subset; intersects
would keep ranges like ^12.0.0 or >=11 that a stale lockfile still
resolves below the floor. Non-semver specifiers (dist-tags,
workspace:, git URLs) are warned about, never rewritten.

The ^12.4.0 constant deliberately duplicates dependencies.firebase
from src/package.json rather than deriving it at build time: the
build's version-injection machinery (versions.json) is under
discussion in angular#3715, so this stays the minimal bridge that machinery
can later supersede. A spec reads src/package.json and fails the
suite if the two values ever drift.

Refs angular#3684
Refs angular#3681
Refs angular#3682
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant