eddyP23
eddyP23

Reputation: 6825

firebase importing just the required packages

I am using firebase within my Angular 6 application and when I use imports like the following,

import { auth, User } from 'firebase';

I get this warning in the browser console:

It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.

For the module builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):

CommonJS Modules:
const firebase = require('firebase/app');
require('firebase/<PACKAGE>');

ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';

Whenever I switch the imports to something like import * as auth from 'firebase/auth':

Upvotes: 2

Views: 2395

Answers (1)

camden_kid
camden_kid

Reputation: 12813

According to danfri86's comment to this GitHub issue - https://github.com/firebase/angularfire/issues/968 - you should do the following:

import firebase from 'firebase/app';
import 'firebase/auth'; // This line is important

export const googleProvider = new firebase.auth.GoogleAuthProvider();

This is in fact what the warning says to do:

ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';

I've just tested it and it doesn't throw any errors.

Upvotes: 2

Related Questions