From 667be2242e7a88d169d437fbde9f3dd64f520c2d Mon Sep 17 00:00:00 2001 From: Armando Navarro Date: Wed, 25 Nov 2026 13:57:56 -0800 Subject: [PATCH 1/5] docs(messaging): say Messaging can be null, and check in the example Messaging is null during server rendering, and with the fix for #3672 also in a browser with no service worker support. The page showed inject(Messaging) with no mention of either. The example service used the injected value in its constructor, so an app copied from it failed to render in those browsers. Add one sentence after the injection snippet, and null checks in the example's constructor, message$ and unregister. Refs #3672 --- docs/messaging.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/docs/messaging.md b/docs/messaging.md index 62b8d9d08..774cd4d94 100644 --- a/docs/messaging.md +++ b/docs/messaging.md @@ -42,6 +42,8 @@ export class AppComponent { } ``` +`Messaging` is `null` during server rendering and in a browser with no service worker support, such as an iOS in-app browser or a page served over plain HTTP to another device, so check it before use. + # Create a Firebase Messaging Service Worker There are two parts to Firebase Messaging, a Service Worker and the DOM API. Angular Fire Messaging allows you to request permission, register this app instance, observe when it is registered or unregistered, and subscribe to messages on the DOM side. To register to receive notifications you need to set up the Service Worker. [The official Firebase documentation for setting up the details exactly how to do that](https://firebase.google.com/docs/cloud-messaging/js/client). @@ -96,10 +98,15 @@ export class FcmService { /* `onMessage` converted to an observable. Returns the unsubscribe function returned by * `onMessage` to stop the listener when the last subscriber unsubscribes. */ message$ = new Observable( - subscriber => onMessage(this.msg, (msg) => subscriber.next(msg)) + subscriber => this.msg ? onMessage(this.msg, (msg) => subscriber.next(msg)) : undefined ).pipe(tap((msg) => console.log("My Firebase Cloud Message", msg))); constructor(private msg: Messaging) { + // `Messaging` is null during server rendering and where the browser has no service workers. + if (!this.msg) { + return; + } + // Set listeners before calling `register` to avoid throwing. this.listenForRegistrationChanges(); this.registerForMessages(); @@ -144,6 +151,10 @@ export class FcmService { // Called from your app, for example when a user turns notifications off. async unregister() { + if (!this.msg) { + return; + } + // This calls the imported unregister, not this method. Class methods are not in lexical scope. await unregister(this.msg); } From d12005e7d2cdebef2d76cdad5b0533ff5562dd32 Mon Sep 17 00:00:00 2001 From: Armando Navarro Date: Wed, 25 Nov 2026 10:59:51 -0800 Subject: [PATCH 2/5] docs: say RemoteConfig is null during server rendering AngularFire creates no Remote Config instance on the server, so inject(RemoteConfig) returns null there while its type says RemoteConfig. The page showed the injection without mentioning it. --- docs/remote-config.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/remote-config.md b/docs/remote-config.md index 3add6c782..5bb8753e0 100644 --- a/docs/remote-config.md +++ b/docs/remote-config.md @@ -44,6 +44,8 @@ export class RemoteConfigComponent { } ``` +`RemoteConfig` is `null` during server rendering, so check it before use. + ## Firebase API AngularFire wraps the Firebase JS SDK to ensure proper functionality in Angular, while providing the same API. From 68a8abbdd7fb316b3d7e078a7616a4b8b7b3de41 Mon Sep 17 00:00:00 2001 From: Armando Navarro Date: Thu, 3 Dec 2026 00:45:59 -0800 Subject: [PATCH 3/5] docs(testing): correct the builder range and put long errors in blocks The step that adds the setup file to include in tsconfig.spec.json is needed on @angular/build 21.2 to 22.1, not only on 21.2. Measured on 21.0.6, 21.1.5, 21.2.0, 21.2.31, 22.0.0, 22.0.9, 22.1.9, 22.2.0, 22.2.8 and 22.3.0. The page now says to always add it, which works on all of them. Four error messages longer than 80 characters move from inline code into fenced blocks after the sentence that introduces them. --- docs/testing.md | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/docs/testing.md b/docs/testing.md index e7457d4bd..49cf55c8f 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -205,7 +205,13 @@ With isolation on, every spec file loads its imports again, so the run takes lon #### Mock the package, not your own files -Angular's Vitest setup rejects `vi.mock('./user-badge')` with the error: `The "vi.mock" and related methods are not supported for relative imports with the Angular unit-test system`. Replace your own services through `TestBed` providers. +Angular's Vitest setup rejects `vi.mock('./user-badge')` with this error: + +``` +The "vi.mock" and related methods are not supported for relative imports with the Angular unit-test system +``` + +Replace your own services through `TestBed` providers. #### Jest example @@ -306,7 +312,13 @@ it('shows the signed-out state', () => { *Applies to the modular API.* -Unlike `Auth`, these cannot be replaced with a plain object. `collection(fakeFirestore, 'items')` throws `Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore`. `ref(fakeStorage, 'file.txt')` throws `Cannot read properties of undefined (reading 'path')`. +Unlike `Auth`, these cannot be replaced with a plain object. `collection(fakeFirestore, 'items')` throws: + +``` +Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore +``` + +`ref(fakeStorage, 'file.txt')` throws `Cannot read properties of undefined (reading 'path')`. Do this instead: use [real services with made-up options](#use-real-services-with-made-up-options) when the code only builds references, and [mock the module](#mock-the-module) when it reads data. @@ -314,7 +326,13 @@ Do this instead: use [real services with made-up options](#use-real-services-wit *Applies to the modular API.* -The full message is `Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app).` Something asked for the default Firebase app and none exists. In a test this has three causes: +The full message is: + +``` +Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app). +``` + +Something asked for the default Firebase app and none exists. In a test this has three causes: - **The code under test calls `getAuth()`, `getFirestore()` or a similar function itself.** Adding `provideFirebaseApp` to the test is not enough, because it creates the app only when something injects `FirebaseApp` or a service that depends on it, such as `Auth`. Do one of these: - Create the app before creating the component, with `TestBed.runInInjectionContext(() => initializeApp(fakeOptions))`. Configure `TestBed` first, because it cannot be configured after this call. @@ -405,7 +423,13 @@ Karma runs the tests in a real browser, and AngularFire needs no extra test conf *Applies to the modular API.* -The [fake `Auth` object](#give-auth-a-fake-object) works under Jasmine, but the last line of its example does not compile. Jasmine's types check the expected value against `User`, and the build stops with `TS2345: Argument of type '{ uid: string; getIdToken: () => Promise; }' is not assignable to parameter of type 'Expected'`. Give `expect` the type `unknown`: +The [fake `Auth` object](#give-auth-a-fake-object) works under Jasmine, but the last line of its example does not compile. Jasmine's types check the expected value against `User`, and the build stops with: + +``` +TS2345: Argument of type '{ uid: string; getIdToken: () => Promise; }' is not assignable to parameter of type 'Expected' +``` + +Give `expect` the type `unknown`: ```ts expect(await firstValueFrom(component.user$)).toEqual(fakeUser); @@ -505,6 +529,6 @@ Three things change after migrating to Vitest: - The real compat `AngularFireAuth` no longer runs. [Replace the compat service](#replace-a-compat-service) in the tests that use it. - A cleanup hook written once for the whole Karma run now covers only its own spec file. Two ways to handle it (either works): - - Move it to a file listed in the `setupFiles` option of the `test` target. If using `@angular/build` 21.2, add that file to `include` in `tsconfig.spec.json` as well. Or + - Move it to a file listed in the `setupFiles` option of the `test` target. Add that file to `include` in `tsconfig.spec.json` as well. `@angular/build` 21.2 to 22.1 need it. Or - Copy it into every spec file that creates an app. - A module mock can take over the job of a wrapper object. Read the notes under [Mock the module](#mock-the-module) before using `vi.mock`. From 84a818c77bb4e69ab4003073f0be76415600f5b0 Mon Sep 17 00:00:00 2001 From: Armando Navarro Date: Thu, 3 Dec 2026 10:44:57 -0800 Subject: [PATCH 4/5] docs(deploy): describe the ng deploy setup that ng add writes Documents #3851: the deploy question in ng add, what it writes for Firebase App Hosting and Firebase Hosting, how ng deploy picks the Firebase project, and the three behavior changes in the upgrade guide. The deploy guide drops its out-of-date note and its siteTarget section, whose option does not exist. --- docs/app-hosting.md | 14 +- docs/deploy/getting-started.md | 312 +++++++++++++++++------------- docs/install-and-setup.md | 16 +- docs/version-22-upgrade.md | 15 ++ site/src/get-started/deploying.md | 2 +- 5 files changed, 219 insertions(+), 140 deletions(-) diff --git a/docs/app-hosting.md b/docs/app-hosting.md index d72eca28b..a330785ab 100644 --- a/docs/app-hosting.md +++ b/docs/app-hosting.md @@ -8,9 +8,21 @@ This guide covers one thing that trips up almost every new SSR deployment: **the server can silently stop server-rendering and fall back to client-side rendering (CSR), with no error anywhere obvious.** It explains how to detect that in 30 seconds and how to fix it. +## Contents + +- [How to deploy](#how-to-deploy) +- [The symptom: SSR silently downgrades to CSR](#the-symptom-ssr-silently-downgrades-to-csr) +- [The 30-second check to run after every deploy](#the-30-second-check-to-run-after-every-deploy) +- [Why it happens](#why-it-happens) +- [The Fix](#the-fix) + - [Why both steps](#why-both-steps) +- [Related Angular documentation](#related-angular-documentation) + ## How to deploy -If you have not deployed yet, follow Firebase's own guides: [Get started with App Hosting](https://firebase.google.com/docs/app-hosting/get-started) to connect a GitHub repository (App Hosting builds and deploys on every push), or [Alternative ways to deploy](https://firebase.google.com/docs/app-hosting/alt-deploy) to deploy with `firebase deploy` from your own machine. Both build your app the same way in Google Cloud Build. The rest of this guide covers an Angular-specific issue you can hit once your app is deployed either way. +If you have not deployed yet, `ng add @angular/fire` can set up `ng deploy` for App Hosting. The [deploy guide](deploy/getting-started.md) explains how. `ng deploy` uploads your workspace the way `firebase deploy` does. + +You can also follow Firebase's own guides: [Get started with App Hosting](https://firebase.google.com/docs/app-hosting/get-started) to connect a GitHub repository (App Hosting builds and deploys on every push), or [Alternative ways to deploy](https://firebase.google.com/docs/app-hosting/alt-deploy) to deploy with `firebase deploy` from your own machine. All of these build your app the same way in Google Cloud Build. The rest of this guide covers an Angular-specific issue you can hit once your app is deployed any of these ways. ## The symptom: SSR silently downgrades to CSR diff --git a/docs/deploy/getting-started.md b/docs/deploy/getting-started.md index d85a2c06b..69e4d4b9e 100644 --- a/docs/deploy/getting-started.md +++ b/docs/deploy/getting-started.md @@ -1,206 +1,250 @@ -# Deploy your application on Firebase Hosting & Functions +# Deploy your application with `ng deploy` -> **This page is out of date.** It describes a setup flow that `ng add @angular/fire` no longer performs. Deploying server-side rendering to Cloud Functions with `ng deploy` (a deploy target with `ssr: true`, and the `functionsRuntimeOptions` and `CF3v2` options only it reads) is deprecated in AngularFire 22 and will be removed in AngularFire 23. Hosting-only deploys (`ssr` absent or `false`) are not deprecated. For current guidance see [the Quickstart](../install-and-setup.md), step 6, and for server-side rendered apps see the [App Hosting guide](../app-hosting.md). +`ng add @angular/fire` sets up the Angular CLI's `ng deploy` command for your app. It can deploy to Firebase App Hosting or to Firebase Hosting. -In this guide, we'll look at how to use `@angular/fire` to automatically deploy an Angular application to Firebase hosting or functions by using the Angular CLI. +## Contents -`@angular/fire` uses Firebase functions to deploy your Angular universal projects, with server-side rendering enabled. +- [Choose where to deploy](#choose-where-to-deploy) +- [Set up deployment](#set-up-deployment) + - [Firebase App Hosting](#firebase-app-hosting) + - [Firebase Hosting](#firebase-hosting) +- [Deploy](#deploy) + - [Preview a Hosting deploy](#preview-a-hosting-deploy) +- [Which Firebase project `ng deploy` uses](#which-firebase-project-ng-deploy-uses) +- [Older setups: Cloud Functions and Cloud Run](#older-setups-cloud-functions-and-cloud-run) + - [Configuring Cloud Functions](#configuring-cloud-functions) -**Angular Universal deployments work with `@nguniversal/*` version 9.0.0 and above**. +## Choose where to deploy -## Step 1: add `@angular/fire` to your project +- **Firebase App Hosting** builds your app in Google Cloud and runs its Node server. Use it for an app that uses server-side rendering (SSR). +- **Firebase Hosting** serves static files. Use it for a client-side rendered app, or for one that is fully prerendered. Hosting cannot run a server. If your app uses SSR, every route that is not prerendered loads as a client-rendered page. -First, you need to add the `@angular/fire` package to your project. In your Angular CLI project run: +App Hosting needs: + +- The Blaze pricing plan on the Firebase project. +- App Hosting's Terms of Service accepted in the Firebase console. +- An account with the Owner or IAM Admin role on the project, for the first deploy to a region. +- Firebase CLI (`firebase-tools`) 15.9.0 or later. Hosting works with 14.0.0 or later. + +## Set up deployment ```shell ng add @angular/fire ``` -*Note that the command above assumes you have global Angular CLI installed. To install Angular CLI globally run `npm i -g @angular/cli`.* +After the features prompt, `ng add` asks "How do you want to deploy this app?" and offers: + +- Firebase App Hosting (server-side rendering) +- Firebase Hosting (static and client-rendered apps) +- Don't set up deployment + +The prompt starts on App Hosting when your app uses SSR, and on Hosting otherwise. To answer it on the command line, pass `--deploy=apphosting`, `--deploy=hosting` or `--deploy=none`. + +To set up deployment in an app that already uses AngularFire, run `ng add @angular/fire` again and press Enter at the features prompt without selecting anything. The deploy prompt starts on what the app already deploys with. + +In a workspace with several applications, specify the one to set up: + +```shell +ng add @angular/fire --project=[PROJECT_NAME] +``` + +### Firebase App Hosting -First, the command above will check if you have an Angular universal project. It'll do so by looking at your `angular.json` project, looking for a `server` target for the specified project. If it finds one, it'll ask you if you want to deploy the project in a firebase function. +`ng add` prints what App Hosting needs. Then it asks which backend to deploy to, or creates one from an id and a region. A backend is what App Hosting deploys an app to. -After that it will trigger the `@angular/fire` `ng-add` schematics. The schematics will open a web browser and guide you through the Firebase authentication flow (if you're not signed in already). After you authenticate, you'll see a prompt to select a Firebase hosting project. +It writes two things. -The schematics will do the following: +A `deploy` target for your project in `angular.json`: -- Add `@angular/fire` to your list of dependencies -- Create `firebase.json`, `.firebaserc` files in the root of your workspace. You can use them to configure your firebase hosting deployment. Find more about them [here](https://firebase.google.com/docs/hosting/full-config) -- Update your workspace file (`angular.json`) by inserting the `deploy` builder +```json +"deploy": { + "builder": "@angular/fire:deploy", + "options": { + "version": 2, + "appHostingBackend": "my-backend" + } +} +``` -In the end, your `angular.json` project will look like below: +An `apphosting` entry in `firebase.json`: -```json5 +```json { - "$schema": "./node_modules/@angular/cli/lib/config/schema.json", - "version": 1, - "newProjectRoot": "projects", - "projects": { - "sample-app": { - // ... - "deploy": { - "builder": "@angular/fire:deploy", - "options": {} // Here you may find an "ssr": true option if you've - // selected that you want to deploy your Angular universal project - // as a firebase function. - } - } - }, - // ... - "defaultProject": "sample-app" - + "apphosting": { + "backendId": "my-backend", + "rootDir": ".", + "ignore": ["node_modules", ".git", "/dist", ".angular", "firebase-debug.log"] + } } ``` -If you want to add deployment capabilities to a different project in your workspace, you can run: +Two things to know: +- If you pick a backend that is connected to a GitHub repository, `ng add` asks you to confirm. `ng deploy` uploads your local files, and that replaces what GitHub last rolled out. +- App Hosting builds your app by running `npm run build`. In a workspace with more than one application, make sure the `build` script in `package.json` builds the application you are deploying. + +### Firebase Hosting + +`ng add` asks which Hosting site to deploy to, or creates one. Then it writes three things. + +A `deploy` target for your project in `angular.json`: + +```json +"deploy": { + "builder": "@angular/fire:deploy", + "options": { + "version": 2 + } +} ``` -ng add @angular/fire --project=[PROJECT_NAME] + +A `hosting` entry in `firebase.json`, with your Angular project's name as its `target`: + +```json +{ + "hosting": [ + { + "target": "my-app", + "public": "dist/my-app/browser", + "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], + "rewrites": [{ "source": "**", "destination": "/index.html" }] + } + ] +} ``` -## Step 2: deploying the project +- `public` is the folder your build writes its browser files to. +- The rewrite serves your app's index page for every URL that matches no file, so the Angular router can handle that URL in the browser. +- The index page is `index.html`. When the build prerenders or renders on a server, it is `index.csr.html`. -As the second step, to deploy your project run: +The site that the target `my-app` stands for, in `.firebaserc`: -``` -ng deploy --project=[PROJECT_NAME] +```json +{ + "projects": { "default": "my-firebase-project" }, + "targets": { + "my-firebase-project": { + "hosting": { "my-app": ["my-site-id"] } + } + } +} ``` -*The `--project` option is optional. Learn more [here](https://angular.io/cli/deploy).* +If `firebase.json` already has a `hosting` entry for the app, `ng add` keeps the settings you added to it, such as headers and redirects. -The command above will trigger: +`ng add` prints a warning in two cases: -1. Production build of your application -2. Deployment of the produced assets to the firebase hosting project you selected during `ng add` +- Your app uses SSR. Hosting cannot run its server. +- Your build has the `localize` option. Such a build writes one folder per locale and no index page above them, so the `hosting` entry has to be changed by hand to serve the locale folders. -If you've specified that you want a server-side rendering enabled deployment in a firebase function, the command will also: +## Deploy -1. Create a firebase function in `dist`, which directly consumes `main.js` from your server output directory. -2. Create `package.json` for the firebase function with the required dependencies. -3. Deploy the static assets to firebase hosting and your universal server as a Firebase function. +```shell +ng deploy +``` -If you want to preview your Angular Universal project before we deploy it as a Firebase Function you can run: +In a workspace with several applications, specify the one to deploy: +```shell +ng deploy [PROJECT_NAME] ``` + +With Firebase App Hosting, `ng deploy` uploads your workspace to the backend. App Hosting builds it in Google Cloud, and the backend's address is printed when the rollout finishes. Nothing is built on your machine. + +With Firebase Hosting, `ng deploy`: + +1. Builds your app with its `production` configuration. +2. Uploads the build to your Hosting site. + +If the build fails, nothing is deployed. To build with another configuration, set `buildTarget` in the deploy options, for example `"buildTarget": "my-app:build:staging"`. + +### Preview a Hosting deploy + +```shell ng deploy --preview ``` -We'll create the function and a `package.json` in your project output directory. This way, you can later run `firebase serve` in your project root so you can test everything before deploying. +This builds your app and serves it locally. Press Ctrl+C to stop the preview, then answer whether to deploy. -## Step 3: customization +`--preview` is not available with App Hosting, which has no local build to preview. -To customize the deployment flow, you can use the configuration files you're already familiar with from `firebase-tools`. You can find more in the [firebase documentation](https://firebase.google.com/docs/hosting/full-config). +## Which Firebase project `ng deploy` uses -### Configuring Cloud Functions +- With App Hosting, the default project in `.firebaserc` (`projects.default`) is used. +- With Hosting, the project that has your app's Hosting target in `.firebaserc` is used. -Setting `functionsNodeVersion` and `functionsRuntimeOptions` in your `angular.json` allow you to customize the version of Node.js Cloud Functions is running and run-time settings like timeout, VPC connectors, and memory. +`.firebaserc` can list the target under more than one Firebase project, for example a staging project and a production project. `ng deploy` then deploys only to a project it is told about: + +- Set `firebaseProject` in the deploy options, or pass `--firebase-project=[PROJECT_ID]`. +- Without it, `ng deploy` asks which project to use when it runs in a terminal. +- With no terminal, as in an automated job, it stops with an error that lists the projects. + +Use a project ID in `firebaseProject`. A project alias is not accepted. + +For example, with this in `.firebaserc`: ```json -"deploy": { - "builder": "@angular/fire:deploy", - "options": { - "functionsNodeVersion": 22, - "functionsRuntimeOptions": { - "memory": "2GB", - "timeoutSeconds": 10, - "vpcConnector": "my-vpc-connector", - "vpcConnectorEgressSettings": "PRIVATE_RANGES_ONLY" - } +{ + "projects": { "default": "my-app-staging" }, + "targets": { + "my-app-staging": { + "hosting": { "my-app": ["my-app-staging"] } + }, + "my-app-production": { + "hosting": { "my-app": ["my-app-production"] } } + } } ``` -### Working with multiple Firebase Projects - -If you have multiple build targets and deploy targets, it is possible to specify them in your `angular.json` or `workspace.json`. - -It is possible to use either your project name or project alias in `firebaseProject`. The setting provided here is equivalent to passing a project name or alias to `firebase deploy --project projectNameOrAlias`. - -The `buildTarget` simply points to an existing build configuration for your project. Most projects have a default configuration and a production configuration (commonly activated by using the `--prod` flag) but it is possible to specify as many build configurations as needed. - -You may specify a `buildTarget` and `firebaseProject` in your `options` as follows: +and this in `angular.json`: ```json "deploy": { - "builder": "@angular/fire:deploy", - "options": { - "buildTarget": "projectName:build", - "firebaseProject": "developmentProject" - }, - "configurations": { - "production": { - "buildTarget": "projectName:build:production", - "firebaseProject": "productionProject" - } + "builder": "@angular/fire:deploy", + "options": { + "version": 2, + "buildTarget": "my-app:build:staging", + "firebaseProject": "my-app-staging" + }, + "configurations": { + "production": { + "buildTarget": "my-app:build:production", + "firebaseProject": "my-app-production" } + } } ``` -The above configuration specifies the following: +- `ng deploy` builds the `staging` configuration and deploys it to `my-app-staging`. +- `ng deploy --configuration=production` builds the `production` configuration and deploys it to `my-app-production`. -1. `ng deploy` will deploy the default project with default configuration. -2. `ng deploy projectName` will deploy the specified project with default configuration. -3. `ng deploy projectName --prod` or `ng deploy projectName --configuration='production'` will deploy `projectName` with production build settings to your production environment. +`buildTarget` is optional. Here it gives each Firebase project its own build configuration, which needs a `staging` configuration in your app's `build` target. -All of the options are optional. If you do not specify a `buildTarget`, it defaults to a production build (`projectName:build:production`). If you do not specify a `firebaseProject`, it defaults to the first matching deploy target found in your `.firebaserc` (where your projectName is the same as your Firebase deploy target name). The `configurations` section is also optional. +## Older setups: Cloud Functions and Cloud Run -### Working with multiple project sites +A `deploy` target without `"version": 2` and with `ssr` set deploys your app's server to Cloud Functions or to Cloud Run. -For example, if you have muti sites config in firebase.json like this: -``` -{ - "hosting": [ - { - "target": "custom-site", - "public": "public/my-custom-site", - "ignore": [ - "firebase.json", - "**/.*", - "**/node_modules/**" - ], - "rewrites": [ - { - "source": "**", - "destination": "/index.html" - } - ] - } - ], -``` +- Deploying server-side rendering to Cloud Functions with `ng deploy` (`ssr: true` or `ssr: 'cloud-functions'`, and the `functionsRuntimeOptions` and `CF3v2` options only it reads) is deprecated in AngularFire 22 and will be removed in AngularFire 23. `ng deploy` prints a warning before the build when it runs in that mode. +- Cloud Run deploys (`ssr: 'cloud-run'`) are not deprecated. -If you have multiple build targets and deploy targets, it is possible to specify them in your `angular.json` or `workspace.json`. +To move such an app to App Hosting, run `ng add @angular/fire` again and choose Firebase App Hosting. That replaces the earlier setup. -It is possible to use either your project name or project alias in `siteTarget`. +### Configuring Cloud Functions -You may specify a `siteTarget` in your `options` as follows: +Setting `functionsNodeVersion` and `functionsRuntimeOptions` in your `angular.json` allow you to customize the version of Node.js Cloud Functions is running and run-time settings like timeout, VPC connectors, and memory. ```json "deploy": { "builder": "@angular/fire:deploy", "options": { - "buildTarget": "projectName:build", - "firebaseProject": "developmentProject", - "siteTarget": "yourDefaultSiteTarget" - }, - "configurations": { - "production": { - "buildTarget": "projectName:build:production", - "firebaseProject": "productionProject", - "siteTarget": "yourProdSiteTarget" - }, - "storybook": { - "buildTarget": "projectName:build-storybook", - "firebaseProject": "developmentProject", - "siteTarget": "yourStorybookSiteTarget" + "functionsNodeVersion": 22, + "functionsRuntimeOptions": { + "memory": "2GB", + "timeoutSeconds": 10, + "vpcConnector": "my-vpc-connector", + "vpcConnectorEgressSettings": "PRIVATE_RANGES_ONLY" } } } ``` - -The above configuration specifies the following: - -1. `ng deploy` will deploy the default project with default configuration. -2. `ng deploy projectName` will deploy the specified project with default configuration. -3. `ng deploy projectName --configuration=storybook --siteTarget=mySiteTarget` will deploy `projectName` to `mySiteTarget` with configuration`storybook`. - -All of the options are optional diff --git a/docs/install-and-setup.md b/docs/install-and-setup.md index 1be754cc9..853e9fc72 100644 --- a/docs/install-and-setup.md +++ b/docs/install-and-setup.md @@ -44,7 +44,8 @@ ng add @angular/fire This installs AngularFire and configures your project. `ng add` will: 1. Prompt you to select the features to enable and the Firebase project to use, signing you in to Firebase if needed. -2. Add `provideFirebaseApp(...)`, along with a provider for each feature you select, to your app configuration (for example `app.config.ts`), with your Firebase configuration inlined. No environment files are created. +2. Ask how you want to deploy your app, and set up `ng deploy` for your answer. Step 6 explains the choices. +3. Add `provideFirebaseApp(...)`, along with a provider for each feature you select, to your app configuration (for example `app.config.ts`), with your Firebase configuration inlined. No environment files are created. ### 3. Inject `Firestore` @@ -136,8 +137,15 @@ Once you've created a `items` collection and are inserting documents, you should ### 6. Deploy your app -How you deploy depends on whether your app uses server-side rendering (SSR), which the Angular CLI asks about when you create the project. +In step 2, `ng add` asked how you want to deploy your app. If you chose Firebase App Hosting or Firebase Hosting, deploy with: -**Client-side rendered apps** (the default) build to static files, which you deploy to Firebase Hosting. Follow Firebase's [Hosting quickstart](https://firebase.google.com/docs/hosting/quickstart) to build and deploy your app. +```bash +ng deploy +``` + +- **Firebase App Hosting** runs a Node server, so it fits apps that use server-side rendering (SSR). `ng deploy` uploads your source, and App Hosting builds it in Google Cloud. It needs the Blaze pricing plan and Firebase CLI 15.9.0 or later. +- **Firebase Hosting** serves static files, so it fits client-side rendered and prerendered apps. `ng deploy` builds your app and uploads the build. + +If you chose not to set up deployment, run `ng add @angular/fire` again. Press Enter at the features prompt without selecting anything, then pick a deploy option. -**Server-side rendered apps** run a Node server, so deploy them to [Firebase App Hosting](app-hosting.md), Firebase's recommended path for SSR. That guide also covers a common case where an SSR app silently falls back to client-side rendering after deploying. +The [deploy guide](deploy/getting-started.md) explains what `ng add` writes and what `ng deploy` does with it. For App Hosting, [Deploying SSR to App Hosting](app-hosting.md) also covers a common case where an SSR app silently falls back to client-side rendering after deploying. diff --git a/docs/version-22-upgrade.md b/docs/version-22-upgrade.md index 3528d7202..473c8e67d 100644 --- a/docs/version-22-upgrade.md +++ b/docs/version-22-upgrade.md @@ -82,6 +82,21 @@ For everything else that changed, see the [Firebase JavaScript SDK release notes If you run AngularFire's schematics with the standalone `schematics` command on pnpm with `hoist=false`, add those three packages to your own `package.json`. +## `ng add` sets up `ng deploy` again + +`ng add @angular/fire` now asks how you want to deploy your app: to Firebase App Hosting, to Firebase Hosting, or not at all. For App Hosting and Hosting it writes the `deploy` target in `angular.json` and the matching entries in `firebase.json` and `.firebaserc`, so `ng deploy` works right after it. + +To set up deployment in an app you are upgrading, run `ng add @angular/fire` again and press Enter at the features prompt without selecting anything. The [deploy guide](deploy/getting-started.md) describes each choice. + +If you already deploy with `ng deploy`, three things changed: + +- **Several Firebase projects in `.firebaserc`.** When `.firebaserc` lists your app's Hosting target under more than one Firebase project, `ng deploy` no longer deploys to the first one listed. + - It deploys to the project in the `firebaseProject` deploy option, or in `--firebase-project=[PROJECT_ID]`. + - Without that option it asks which project to use when it runs in a terminal. + - With no terminal, as in an automated job, it stops with an error. Set `firebaseProject` in the deploy options in `angular.json` to fix such a job. +- **A failed build stops the deploy.** `ng deploy` used to go on to the deploy step after a build failed. +- **App Hosting needs Firebase CLI 15.9.0 or later.** Everything else still works with 14.0.0 or later. + ## Deploy builder Deploying server-side rendering to Cloud Functions with `ng deploy` (a deploy target with `ssr: true` or `ssr: 'cloud-functions'`, and the `functionsRuntimeOptions` and `CF3v2` options only it reads) is deprecated in AngularFire 22 and will be removed in AngularFire 23. `ng deploy` prints a warning before the build when it runs in that mode. Server-rendered apps should move to [Firebase App Hosting](./app-hosting.md). diff --git a/site/src/get-started/deploying.md b/site/src/get-started/deploying.md index 566839053..6e82fef79 100644 --- a/site/src/get-started/deploying.md +++ b/site/src/get-started/deploying.md @@ -7,7 +7,7 @@ eleventyNavigation: ## Static or Server-side rendered -> **This page is out of date.** It describes a setup flow that `ng add @angular/fire` no longer performs, and wiring the deploy target by hand from the samples below puts you on a deprecated path that warns on every deploy. For current guidance see [the Quickstart](https://github.com/angular/angularfire/blob/main/docs/install-and-setup.md), step 6, and for server-side rendered apps see the [App Hosting guide](https://github.com/angular/angularfire/blob/main/docs/app-hosting.md). +> **This page is out of date.** `ng add @angular/fire` sets up `ng deploy` differently from what this page describes. For current guidance see the [deploy guide](https://github.com/angular/angularfire/blob/main/docs/deploy/getting-started.md), and for server-side rendered apps see the [App Hosting guide](https://github.com/angular/angularfire/blob/main/docs/app-hosting.md). In this guide, we'll look at how to use `@angular/fire` to automatically deploy an Angular application to Firebase Hosting or Cloud Functions by using the Angular CLI. From 18b1c02576caed1a7d970bb999c62fbe64a666a6 Mon Sep 17 00:00:00 2001 From: Armando Navarro Date: Thu, 3 Dec 2026 11:27:58 -0800 Subject: [PATCH 5/5] docs: describe AngularFire 22 as released, not as a release candidate The upgrade guide drops its release candidate title and the sentence about the next tag, and its commands install @angular/fire@22 instead of @next. A 22.0.1 canary build is told to run npm install, because ng update does not offer 22.0.0 to a higher version number. The Quickstart creates an Angular 22 project. Its npm 11.6 note is removed: npm 10.9.11 installs a new Angular 22.3 project without the edgesOut crash, and npm/cli#9787 is closed as fixed in npm 11. --- docs/install-and-setup.md | 10 ++++------ docs/version-22-upgrade.md | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/docs/install-and-setup.md b/docs/install-and-setup.md index 853e9fc72..be6243320 100644 --- a/docs/install-and-setup.md +++ b/docs/install-and-setup.md @@ -6,34 +6,32 @@ - Setup uses the Firebase CLI (`firebase-tools`). Install it with `npm install -g firebase-tools`, then run `firebase login`. If `ng add` can't find a copy, it installs the newest version for you. - A copy older than 14 stops setup with `firebase-tools version 14.0.0+ is required, please upgrade and run again`, and `ng add` does not upgrade a copy you already have. - If `ng add` stops before finishing, run it again. A stopped run leaves only an empty `firebase.json`, which the next run reuses. -- **npm 11.6 or later**, if you use npm. Older versions, including the npm 10 that ships with Node.js 20 and 22, cannot install a new Angular 21 project ([npm/cli#9787](https://github.com/npm/cli/issues/9787), `Cannot read properties of null (reading 'edgesOut')`). Update with `npm install -g npm@11`. - - If it already failed, delete the project folder it left behind before running the command again. - **Harmless CLI noise.** The Firebase CLI may print a `punycode` deprecation warning or ask about enabling extra features (for example Gemini) during setup. These come from the CLI, not from AngularFire, and are safe to ignore. ### 1. Create a new project ```bash # Using yarn create -yarn create @angular@21 +yarn create @angular@22 cd ``` or ```bash # Using npm create -npm create @angular@21 +npm create @angular@22 cd ``` optionally installing the tooling directly: ```bash # Installing the tooling directly -npm install -g @angular/cli@21 +npm install -g @angular/cli@22 ng new cd ``` -These commands set up an Angular 21 project, the version AngularFire 21 supports. +These commands set up an Angular 22 project, the version AngularFire 22 supports. ### 2. Install AngularFire and Firebase diff --git a/docs/version-22-upgrade.md b/docs/version-22-upgrade.md index 473c8e67d..3433baf66 100644 --- a/docs/version-22-upgrade.md +++ b/docs/version-22-upgrade.md @@ -1,16 +1,16 @@ -# Upgrading to the AngularFire 22 release candidate +# Upgrading to AngularFire 22 AngularFire 22 targets **Angular 22** and the **Firebase JS SDK v12 or v13**. Most of the upgrade is handled for you by `ng update`. ## Run the update -AngularFire 22 is a release candidate, published under the `next` tag. From an app on Angular 21 and AngularFire 21, run: +From an app on Angular 21 and AngularFire 21, run: ```bash -ng update @angular/core@22 @angular/cli@22 @angular/fire@next +ng update @angular/core@22 @angular/cli@22 @angular/fire@22 ``` -Include `@angular/fire@next` in the same command as Angular. On its own, `ng update @angular/core@22 @angular/cli@22` refuses to run while AngularFire 21 is installed, because AngularFire 21 only accepts Angular 21. +Include `@angular/fire@22` in the same command as Angular. On its own, `ng update @angular/core@22 @angular/cli@22` refuses to run while AngularFire 21 is installed, because AngularFire 21 only accepts Angular 21. The AngularFire update runs a migration that: @@ -25,17 +25,17 @@ Through AngularFire 21, `@angular/fire` listed `firebase` under `dependencies`, AngularFire 22 lists `firebase` under `peerDependencies` instead. So your app should declare `firebase` in its `package.json` (on Yarn it must, since Yarn installs no peer dependencies). This gives you exactly one copy of `firebase`. When your `package.json` requests an incompatible version, npm refuses to install it and Yarn and pnpm warn (see below), instead of the app failing at runtime. -`ng update @angular/fire@next` updates an older `firebase` entry in your `package.json` when it requests a version outside `^12.18.0 || ^13.0.0`. If your app doesn't list `firebase` in `package.json`, the migration adds it and reinstalls. Verify with `npm ls firebase`, which should show exactly one copy. +`ng update @angular/fire@22` updates an older `firebase` entry in your `package.json` when it requests a version outside `^12.18.0 || ^13.0.0`. If your app doesn't list `firebase` in `package.json`, the migration adds it and reinstalls. Verify with `npm ls firebase`, which should show exactly one copy. ### If you install with `npm install` instead of `ng update` Add the dependency yourself: ```bash -npm install @angular/fire@next firebase@^12.18.0 +npm install @angular/fire@22 firebase@^12.18.0 ``` -npm 7 and later install a missing peer dependency automatically, so `npm install @angular/fire@next` alone also works, but it does not write `firebase` into your `package.json`. Declare it so that a later install cannot change which version you get. +npm 7 and later install a missing peer dependency automatically, so `npm install @angular/fire@22` alone also works, but it does not write `firebase` into your `package.json`. Declare it so that a later install cannot change which version you get. ### If npm stops with `ERESOLVE` @@ -49,7 +49,7 @@ Do not use `--force` or `--legacy-peer-deps` to get past this message. Both inst ### Yarn -Yarn doesn't install peer dependencies. Add `firebase` to your own `package.json` as shown above, or run `ng update @angular/fire@next`, which adds it. +Yarn doesn't install peer dependencies. Add `firebase` to your own `package.json` as shown above, or run `ng update @angular/fire@22`, which adds it. An older version installs anyway with a warning (`has incorrect peer dependency "firebase@^12.18.0 || ^13.0.0"` on Yarn 1, `YN0060: INCOMPATIBLE_PEER_DEPENDENCY` on Yarn 2+), so treat that warning as an upgrade step you still have to do. @@ -130,9 +130,9 @@ Every callback read (`onSnapshot`, `onAuthStateChanged`, `onValue` and the other - **Node.js 20 is not supported.** Angular 22 requires Node.js `^22.22.3 || ^24.15.0 || >=26.0.0`. Node.js 20 reached end of life on 2026-04-30. - **TypeScript 6.0 is required** (AngularFire 22 peers `typescript >=6.0 <6.1`). TypeScript 6 turns `strict` on by default, drops `downlevelIteration` and deprecates `baseUrl` and `moduleResolution: "node"`, so an app carrying those settings in its `tsconfig.json` may see new compiler errors that Angular's own update does not fix. - **Coming from a 21 release candidate** (`21.0.0-rc.0`, `rc.1` or `rc.2`), the v21 migration runs once more and reports "No changes made", because `21.0.0` lies between your version and `22.0.0`. That is expected. -- **Coming from `22.0.0-rc.0`,** run `ng update @angular/fire@next`. +- **Coming from a 22 release candidate** (`22.0.0-rc.0` or `rc.1`), run `ng update @angular/fire@22`. - `ng add` saved the release candidate as an exact version, so it does not move on its own. - The v22 migration runs once more and reports "No changes made" when your `firebase` entry is already inside the supported range. -- **Coming from a 22 canary build.** On `22.0.0-canary.*`, run `ng update @angular/fire@next`. On `22.0.1-canary.*`, run `ng update @angular/fire@canary`. +- **Coming from a 22 canary build.** On `22.0.0-canary.*`, run `ng update @angular/fire@22`. On `22.0.1-canary.*`, run `npm install @angular/fire@22`, because `ng update` does not offer `22.0.0` to a version numbered above it. - **Screen tracking** (`ScreenTrackingService`) reads the routed component's selector through Angular's `reflectComponentType`, because `ComponentFactoryResolver` is gone from Angular 22. Nothing changes for your app. - **Server rendering in one call.** `initializeBrowserOrServerApp` from `@angular/fire/app` replaces the `provideFirebaseApp` callback the Authentication guide used to ask server-rendered apps to write. It builds the ordinary app in the browser and a `FirebaseServerApp` for the visitor's tokens on the server, releases it, and renders signed out instead of failing on a token Firebase cannot parse. See [Server-side Rendering](auth.md#server-side-rendering). Existing callbacks keep working.