Skip to content

@angular/fire@17.0.0 throws Circular dependency in DI detected for Analytics. when using Analytics feature #3476

@jakehockey10

Description

@jakehockey10

Version info

Versions:

$ ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 17.0.6
Node: 20.1.0
Package Manager: npm 9.7.1
OS: linux x64

Angular: 17.0.6
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1700.6
@angular-devkit/build-angular   17.0.6
@angular-devkit/core            17.0.6
@angular-devkit/schematics      17.0.6
@angular/cdk                    17.0.2
@angular/fire                   17.0.0
@angular/google-maps            17.0.2
@angular/material               17.0.2
@schematics/angular             17.0.6
ng-packagr                      17.0.0
rxjs                            7.8.1
typescript                      5.2.2
zone.js                         0.14.2

How to reproduce these conditions

Failing test unit, Stackblitz demonstrating the problem

Steps to set up and reproduce

in app.config.ts, provide the analytics feature:

importProvidersFrom([
  provideFirebaseApp(() => initializeApp(environment.firebase)),
  provideAnalytics(() => getAnalytics()),
  provideAuth(() => getAuth()),
  provideFirestore(() => getFirestore()),
  provideFunctions(() => {
    const functions = getFunctions();
    // connectFunctionsEmulator(functions, 'localhost', 5001);
    return functions;
  }),
  providePerformance(() => getPerformance()),
  provideStorage(() => getStorage()),
]),

Sample data and security rules

Debug output

** Errors in the JavaScript console **

debug.operator.ts:31 ERROR FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app).
    at getApp (index.esm2017.js:479:29)
    at getAnalytics (index.esm2017.js:1059:35)
    at angular-fire.mjs:202:48
    at angular-fire.mjs:134:59
    at _ZoneDelegate.invoke (zone.js:368:26)
    at Zone.run (zone.js:129:43)
    at NgZone.runOutsideAngular (core.mjs:14591:28)
    at runOutsideAngular (angular-fire.mjs:134:35)
    at angular-fire.mjs:202:21
    at firebase.provider.ts:22:42
ERROR Error: NG0200: Circular dependency in DI detected for Analytics. Find more at https://angular.io/errors/NG0200
    at throwCyclicDependencyError (core.mjs:292:11)
    at R3Injector.hydrate (core.mjs:6162:13)
    at R3Injector.get (core.mjs:6037:33)
    at angular-fire-analytics.mjs:196:40
    at _ZoneDelegate.invoke (zone.js:368:26)
    at Object.onInvoke (core.mjs:14695:33)
    at _ZoneDelegate.invoke (zone.js:367:52)
    at Zone.run (zone.js:129:43)
    at zone.js:1257:36
    at _ZoneDelegate.invokeTask (zone.js:402:31)

If I comment out where I provide Analytics, then Performance runs into an issue:

main.ts:6 NullInjectorError: R3InjectorError(Standalone[AppComponent])[Performance -> Performance -> Performance]: 
  NullInjectorError: No provider for Performance!
    at NullInjector.get (core.mjs:5605:27)
    at R3Injector.get (core.mjs:6048:33)
    at R3Injector.get (core.mjs:6048:33)
    at R3Injector.get (core.mjs:6048:33)
    at ChainedInjector.get (core.mjs:15400:36)
    at lookupTokenUsingModuleInjector (core.mjs:4116:39)
    at getOrCreateInjectable (core.mjs:4164:12)
    at ɵɵdirectiveInject (core.mjs:11974:19)
    at ɵɵinject (core.mjs:917:60)
    at inject (core.mjs:1001:12)

** Output from firebase.database().enableLogging(true); **

** Screenshots **

Expected behavior

Actual behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions