Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The inability to load a firebase service twice breaks co-existance of firebase and firebase-admin in a project #974

Closed
remie opened this issue Jun 30, 2018 · 3 comments

Comments

@remie
Copy link

remie commented Jun 30, 2018

Describe your environment

  • Operating System version: OSX High Sierra
  • Browser version: N/A
  • Firebase SDK version: 5.0.x
  • Firebase Product: firebase-js-sdk & firebase-admin

Describe the problem

You cannot combine firebase 5.x loading mechanism with firebase-admin.

Steps to reproduce:

Starting with firebase 5, the new way of importing firebase and the firebase services is

import * as firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/storage';
import 'firebase/database';

Which of course is totally cool if someone would have also told the 'firebase-admin' team. Because if you add one single line to your import statement:

import * as admin from 'firebase-admin';
import * as firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/storage';
import 'firebase/database';

the application will totally freak out and throw an error saying 'Firebase: Firebase service named \'database\' already registered (app/duplicate-service).'

I haven't really looked into the code but I'm guessing that the import 'firebase/database' is pro-actively registering the database service for the default firebase instance. The firebase-admin probably also has an import of 'firebase/database' somewhere which will cause the database service to try and register twice.

A possible solution would be to remove the code block which tells us that we cannot register a service twice and simply return the existing instance if the service already exists.

Relevant Code:

A workaround seems to be to make the imports dynamic:

const fb = firebase.initializeApp(config, name);
if (!(<any>fb).services_['auth'] || !(<any>fb).services_['auth'][fb.name]) require('firebase/auth');
if (!(<any>fb).services_['storage'] || !(<any>fb).services_['storage'][fb.name]) require('firebase/storage');
if (!(<any>fb).services_['database'] || !(<any>fb).services_['database'][fb.name]) require('firebase/database');
@google-oss-bot
Copy link
Contributor

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@google-oss-bot
Copy link
Contributor

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@jshcrowthe
Copy link
Contributor

Duplicate of #752

@jshcrowthe jshcrowthe marked this as a duplicate of #752 Jul 2, 2018
@firebase firebase locked and limited conversation to collaborators Oct 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants