Arata Kaizaki
Arata Kaizaki

Reputation: 57

"store is not defined" Firebase and ReactJS error

I am currently working on creating a music player using react and decided to use Firebase to store data and host my site. However, when I try to start up my development server through npm start, I come across the following error:

Failed to compile
Line 19:1: 'store' is not defined
Line 24:26: 'store' is not defined
Line 25:22: 'store' is not defined

To install Firebase, I ran npm install --save firebase and connected my local project to my Firebase project through firebase init.

I wrote the following (note: I chose to write "a" for firebase config fields for privacy/security reasons):

import * as firebase from "firebase/app"
import "firebase/firestore"
import "firebase/storage"

const firebaseConfig = {
  apiKey: "a",
  authDomain: "a",
  databaseURL: "a",
  projectId: "a",
  storageBucket: "a",
  messagingSenderId: "a",
  appId: "a",
  measurementId: "a"
};

firebase.initializeApp(firebaseConfig)
store = firebase.firestore() // Line 19

Here is what I wrote for lines 24-25:

const cloudPlaylists = store.collection("playlists"); // Line 24
const cloudSongs = store.collection("songs"); // Line 25

I've looked at it for some time and I still can't figure out how I am getting this error, I've used Firebase before and never came across this issue before, so I'm completely stuck. Any help or feedback is appreciated in helping me solve this issue. Thank you.

Upvotes: 0

Views: 134

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317878

You have to declare a variable before you can use it.

const store = firebase.firestore()

Upvotes: 1

Related Questions