简体   繁体   English

“商店未定义” Firebase 和 ReactJS 错误

[英]"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.我目前正在使用 react 创建音乐播放器,并决定使用 Firebase 来存储数据和托管我的网站。 However, when I try to start up my development server through npm start , I come across the following error:但是,当我尝试通过npm start我的开发服务器npm start ,我遇到了以下错误:

Failed to compile编译失败
Line 19:1: 'store' is not defined第 19:1 行:未定义“商店”
Line 24:26: 'store' is not defined第 24:26 行:未定义“商店”
Line 25:22: 'store' is not defined第 25:22 行:未定义“商店”

To install Firebase, I ran npm install --save firebase and connected my local project to my Firebase project through firebase init .为了安装 Firebase,我运行了npm install --save firebase并通过firebase init将我的本地项目连接到我的 Firebase 项目。

I wrote the following (note: I chose to write "a" for firebase config fields for privacy/security reasons):我写了以下内容(注意:出于隐私/安全原因,我选择为 firebase 配置字段写“a”):

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:这是我为第 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.我已经看了一段时间,但我仍然无法弄清楚我是如何得到这个错误的,我以前使用过 Firebase 并且以前从未遇到过这个问题,所以我完全被卡住了。 Any help or feedback is appreciated in helping me solve this issue.感谢任何帮助或反馈帮助我解决这个问题。 Thank you.谢谢你。

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

const store = firebase.firestore()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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