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')
?
This worked for me:
From https://github.com/firebase/reactfire#using-the-firebase-js-sdk-in-react
My trouble was that I was trying to use ES6 syntax. The Firebase docs say to access it via something like:
Whereas I wanted to do something like this:
That didn't seem to work, but this does:
I don't like mixing
import
andrequire
, but good enough for now.I created a config file for firebase:
Then I just import this module to file where I want to use. For example:
Two months later, this is working for me:
(It also works without the '@'.)
Here's the dependencies section from my package.json:
I started out following the instructions on npmjs.com for the firebase package. In its dependencies, I found @firebase/firestore, and tried to follow those instructions, which say to import like this:
However, this method of importing firebase didn't work for me -- I was able to initialize my app, but trying to execute
firebase.auth().signInWithPopup(provider)
caused an error: