Repository navigation
AngularFireModule from @angular/fire/compat not providing the database appropriately. #3683
Description
Activity
- addedcomp: compatCompatibility layer for the pre-modular API (src/compat).Compatibility layer for the pre-modular API (src/compat).needs: more infoWaiting on the reporter for repro, versions, or detail.Waiting on the reporter for repro, versions, or detail.type: bugDefect: expected behavior doesn't happen.Defect: expected behavior doesn't happen.version: current (v17+)Targets the current modular API (v17+).Targets the current modular API (v17+).
on Jul 25, 2026 Thanks for the report.
The thing to flag first:
Database2is the name the bundler gives AngularFire's modularDatabaseDI token, so this error is about the modularDatabaseprovider, but your pasted service injects the compatAngularFireDatabasefrom@angular/fire/compat/database. Those two do not line up, and that mismatch is the useful clue here.The compat
AngularFireDatabasedoes not depend on the modularDatabasetoken at all; it depends onFIREBASE_OPTIONS, which comes fromAngularFireModule(compat), not from your modularprovideDatabase. So the compat service as pasted would fail looking forFIREBASE_OPTIONS, not with aDatabase2error. And since you have already addedprovideDatabase(() => getDatabase())at the root, a plain modularDatabaseinjection at the root should resolve, so "no provider" is surprising.That points at one of a couple of things, and both assume something in your app is injecting the modular
Databasetoken (the compat service you pasted does not, which is itself the first thing to sort out):- Two copies of
@angular/firein the tree: theDatabaseclass your code imports is then a different class object than the oneprovideDatabaseregistered, so the injector has no provider for the exact token you asked for.npm ls @angular/firewill show a duplicate. (A duplicatefirebaseon its own is a different, runtime symptom, not this DI error.) - Less likely, a lazy-loaded route or child injector that re-declares its own
Databaseprovider and so shadows the root one.
To actually fix it, pick one API and stay in it. compat and modular are separate DI systems:
- Modular (matches the
provideDatabase(() => getDatabase())you already have): inject the modular token and use modular functions.private db = inject(Database)from@angular/fire/database, thenref(this.db, '/path')withobjectVal/list/listVal. Drop the compat import. - compat (if you specifically want
AngularFireDatabase.list(...).valueChanges()): provide the compat modules instead,importProvidersFrom(AngularFireModule.initializeApp(environment.firebase), AngularFireDatabaseModule), and removeprovideDatabase.
Could you share
npm ls @angular/fireand confirm which service actually throws? Then I can point you at the exact one-line fix rather than guessing.- Two copies of
So I've been facing an issue for the past couple of days where whenever I try to use the AngularFireDatabase database to read or write to my Firebase database my console gives me the error:
No provider found for Database2. Source: Standalone[_Homecomponent].I'm currently running Angular 20.0 as AngularFire 21.0 is yet to be fully fleshed out.
My dummy service to test the data looks like this below:
import { Injectable } from '@angular/core';import { AngularFireDatabase } from '@angular/fire/compat/database';@Injectable({providedIn: 'root'})export class Postingservice {constructor(private afDb:AngularFireDatabase){}viewPosts(){return this.afDb.list("/posts").valueChanges();}}I've both tried instantiating the afDb in the constructor and using the inject() function and neither have worked to any avail.
Here also is my app.config.ts:
import { ApplicationConfig, provideBrowserGlobalErrorListeners, provideZoneChangeDetection } from '@angular/core';import { provideRouter } from '@angular/router';import { initializeApp, provideFirebaseApp } from '@angular/fire/app';import { getDatabase, provideDatabase } from '@angular/fire/database';import { routes } from './app.routes';export const appConfig: ApplicationConfig = {providers: [provideBrowserGlobalErrorListeners(),provideZoneChangeDetection({ eventCoalescing: true }),provideRouter(routes),provideFirebaseApp(() =>initializeApp({// FIREBASE CONFIG DATA})),provideDatabase(() => getDatabase()),]};I've even provided the provideDatabase() function even as it's not necessary for the AngularFireDatabase as a provider and likewise it's been to no avail...
And my application is bootstrapping correctly as it runs just fine until I create an instance of the afDb database in a component where I then get the above stated error. Kindly help.