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

后端 未结 5 1339
余生分开走
余生分开走 2021-01-13 11:20

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 expla

5条回答
  •  灰色年华
    2021-01-13 11:59

    My trouble was that I was trying to use ES6 syntax. The Firebase docs say to access it via something like:

    const firebase = require('firebase');
    require('firebase/firestore');
    

    Whereas I wanted to do something like this:

    import * as Firebase from 'firebase';
    import Firestore from 'firebase/firestore';
    

    That didn't seem to work, but this does:

    import * as Firebase from 'firebase';
    require('firebase/firestore');
    

    I don't like mixing import and require, but good enough for now.

提交回复
热议问题