简体   繁体   English

类型错误:_firebase__WEBPACK_IMPORTED_MODULE_9__.default.collection 不是 function

[英]TypeError: _firebase__WEBPACK_IMPORTED_MODULE_9__.default.collection is not a function

Down below is the code where I am getting an error on.下面是我遇到错误的代码。 This is a WhatsApp clone using react JS and firebase as a server that I am making and I am following the instructions to the teeth but for some reason, I can't fix this annoying bug.这是一个 WhatsApp 克隆,使用 react JS 和 firebase 作为我正在制作的服务器,我正在按照指示进行操作,但由于某种原因,我无法修复这个烦人的错误。 I defined db and imported it as you see below but it is still giving me an error, Plz, help!我定义了 db 并将其导入,如下所示,但它仍然给我一个错误,请帮助! If you need me to clarify or have any other questions please let me know!如果您需要我澄清或有任何其他问题,请告诉我!

enter image description here在此处输入图像描述

import React, { useEffect, useState } from 'react'
import{Avatar, IconButton} from "@material-ui/core";
import DonutLargeIcon from "@material-ui/icons/DonutLarge";
import ChatIcon from "@material-ui/icons/Chat";
import MoreVertIcon from "@material-ui/icons/MoreVert";
import{SearchOutlined} from "@material-ui/icons";
import SidebarChat from "./SidebarChat";
import "./Sidebar.css";
import db from "./firebase";

function Sidebar() { function 边栏(){

 const [rooms, setRooms] = useState([]);

useEffect(() => {
 db.collection("rooms").onSnapshot((snapshot) => 
    setRooms(snapshot.docs.map((doc) =>({
            id: doc.id,
            data: doc.data(),
        }))
        )
    );
        }, []);

I went into the firebase.js file and changed the export from the following:我进入 firebase.js 文件并从以下更改导出:

export default {db};

To the following and it removed the error for me:到以下内容,它为我消除了错误:

export default db;

The issue was caused by the brackets in my case.在我的情况下,这个问题是由括号引起的。

暂无
暂无

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

相关问题 类型错误:_firebase__WEBPACK_IMPORTED_MODULE_2__.default.collection 不是函数 - TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.default.collection is not a function 类型错误:_components_firebase__WEBPACK_IMPORTED_MODULE_3__.default.collection 不是函数 - TypeError: _components_firebase__WEBPACK_IMPORTED_MODULE_3__.default.collection is not a function 类型错误:_firebase_firebase__WEBPACK_IMPORTED_MODULE_8__.default.auth 不是 function - TypeError: _firebase_firebase__WEBPACK_IMPORTED_MODULE_8__.default.auth is not a function 类型错误:_fire__WEBPACK_IMPORTED_MODULE_11__.default.collection 不是 function - TypeError: _fire__WEBPACK_IMPORTED_MODULE_11__.default.collection is not a function 类型错误:firebase_app__WEBPACK_IMPORTED_MODULE_0___default.a.analytics 不是 function - TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0___default.a.analytics is not a function 未捕获的类型错误:_firebase__WEBPACK_IMPORTED_MODULE_3__.default.collections 不是 function - Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_3__.default.collections is not a function 如何修复此错误 TypeError: _components_firebase_Firebase__WEBPACK_IMPORTED_MODULE_2__.default.auth is not a function - How do I fix this error TypeError: _components_firebase_Firebase__WEBPACK_IMPORTED_MODULE_2__.default.auth is not a function React/Firebase 错误“未捕获(承诺中)TypeError:(0,_firebase__WEBPACK_IMPORTED_MODULE_1__.default)不是函数” - React/Firebase error "Uncaught (in promise) TypeError: (0 , _firebase__WEBPACK_IMPORTED_MODULE_1__.default) is not a function" typeError: _ firebase_index_WEBPACK_IMPORTED_MODULE_17__.DEFUALT.collection 不是 function - typeError: _ firebase_index_WEBPACK_IMPORTED_MODULE_17__.DEFUALT.collection is not a function "类型错误:firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.firestore 不是函数" - TypeError: firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.firestore is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM