简体   繁体   中英

"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.

您必须先声明一个变量,然后才能使用它。

const store = firebase.firestore()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM