Jus10
Jus10

Reputation: 15669

How to properly import Firestore with TypeScript and Node?

I'm building an Angular web app, and I was importing like this:

import * as firebase from 'firebase';
db = firebase.firestore();

But lately I keep getting this error:

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):

Typescript:
import * as firebase from 'firebase/app';
import 'firebase/<PACKAGE>';

and so, naturally, I changed it to this:

import * as firebase from 'firebase/app';
import 'firebase/firestore';
db = firebase.firestore();

but the error didn't go away. I don't understand how to remove it?

Upvotes: 5

Views: 2861

Answers (1)

Patrick
Patrick

Reputation: 14278

Background

That warning message is only triggered if you're loading the all firebase modules like you are in your first code snippet. It's best practice to only use bare imports like you changed it to:

import * as firebase from 'firebase/app';
import 'firebase/firestore';

This imports just the firestore module.

Solution

Search your imports in any files you changed for from 'firebase'. Even code like import {firestore} from 'firebase'; would trigger the warning message.

Upvotes: 3

Related Questions