Search code examples
reactjsfirebaseecmascript-6create-react-appes6-modules

How to import Firebase Firestore into a create-react-app project using ES6 syntax


I'm having trouble getting Firebase Firestore to work with the basic create-react-app boilerplate. Does anyone have a working sample?

The Get Started doc only explains how to set it up with require statements, whereas I'd like to use ES6 imports.

const firebase = require("firebase");
// Required for side-effects
require("firebase/firestore");

What is the ES6 equivalent of require('firebase/firestore')?


Solution

  • This worked for me:

    import firebase from 'firebase/app';
    import 'firebase/auth';
    import 'firebase/datastore';
    

    From https://github.com/firebase/reactfire#using-the-firebase-js-sdk-in-react