Skip to content

FiresoreSettings with SSR causes No Firebase App '[DEFAULT]' has been created #3643

Closed as not planned
@misomarcell

Description

@misomarcell

In my Angular app I have 3 configuration files: 1 for common providers, 1 for server and 1 for client. I'm initializing Firestore in the common one, like this:

provideFirestore(() => {
	const firestore = initializeFirestore(inject(FirebaseApp), {
		ignoreUndefinedProperties: true,
		localCache: memoryLocalCache()
	});

	if (!environment.production) {
		connectFirestoreEmulator(firestore, "localhost", 8080);
	}

	return firestore;
}),

While on the client it works just fine, my server app throws errors on each reload, saying:
_FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call initializeApp() first (app/no-app).

In the client config I'M initializing the app with provideFirebaseApp(() => initializeApp(environment.firebase)) while for the server, I use

provideFirebaseApp(() => {
  const requestContext = inject(REQUEST_CONTEXT, { optional: true }) as
	| {
			authIdToken: string;
	  }
	| undefined;
  const authIdToken = requestContext?.authIdToken;

  return initializeServerApp(environment.firebase, { authIdToken });
})

I've tried switching the order of providers, using getFirestore() instead, using getApp() instead, but nothing seem to work. Previously when I was still using zone.js, the error didn't cause the app to stop and were complaining about my setting of ignoreUndefinedProperties: true inside the initializeFirestore() I use this setting extensively, so getting rid of it is not an option.

Versions:

"@angular/common": "^19.1.0",
"@angular/fire": "^19.0.0",
"firebase": "^11.3.1",

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