简体   繁体   English

在 Firebase 中,我收到 Uncaught TypeError: Cannot read property 'initializeApp' of undefined,但不确定为什么未定义“firebase”?

[英]In Firebase I am getting an Uncaught TypeError: Cannot read property 'initializeApp' of undefined, but not sure why 'firebase' is not defined?

here's my firebase import etc. in the config file, why would this be unable to recognise firebase?这是配置文件中的我的 firebase 导入等,为什么这无法识别 firebase?

import firebase from 'firebase/app'
import 'firebase/firestore'
import 'firebase/auth'

const firebaseConfig = {
  apiKey: "XXX",
  authDomain: "XXX",
  projectId: "XXX",
  storageBucket: "XXX",
  messagingSenderId: "XXX",
  appId: "XXX",
  measurementId: "XXX"
}

//init firebase
firebase.initializeApp(firebaseConfig)

const projectAuth = firebase.auth()
const projectFirestore = firebase.firestore()
const timestamp = firebase.firestore.FieldValue.serverTimestamp

export { projectAuth, projectFirestore, timestamp }

If you have installed version 9.0.0 then you would have to use compat libraries to use the namespaced version:如果您安装了9.0.0版,则必须使用 compat 库来使用命名空间版本:

import firebase from 'firebase/compat/app'
import 'firebase/compat/firestore'
import 'firebase/compat/auth'

Although I'd recommend using the new Modular syntax which is designed to facilitate tree-shaking (removal of unused code) to make your web app as small and fast as possible.尽管我建议使用新的模块化语法,该语法旨在促进摇树(删除未使用的代码)以使您的 Web 应用程序尽可能小和快速。

import { initializeApp } from "firebase/app"
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore"

const app = initializeApp(firebaseConfig)

const projectAuth = getAuth(app)
const projectFirestore = getFirestore(app)

export { projectAuth, projectFirestore }

You can find detailed information in the documentation您可以在文档中找到详细信息

暂无
暂无

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

相关问题 React JS,Firebase,TypeError:无法读取未定义的属性“initializeApp” - React JS, Firebase, TypeError: Cannot read property 'initializeApp' of undefined 未捕获的类型错误:无法读取未定义的属性“initializeApp” - Uncaught TypeError: Cannot read property 'initializeApp' of undefined 为什么我会收到Uncaught TypeError:无法在分配时读取未定义的属性“ 0”? - why am I getting Uncaught TypeError: Cannot read property '0' of undefined on assign? 我为什么会收到错误:Uncaught TypeError:无法读取未定义的属性“ left” - Why am I getting the error: Uncaught TypeError: Cannot read property 'left' of undefined 为什么会出现Uncaught TypeError:无法读取未定义的属性'displayQuestion'? - Why am i getting Uncaught TypeError: Cannot read property 'displayQuestion' of undefined? 为什么我得到 Uncaught (in promise) TypeError: Cannot read property 'type' of undefined? - Why am I getting Uncaught (in promise) TypeError: Cannot read property 'type' of undefined? 为什么我收到此错误:未捕获的TypeError:无法读取undefined的属性'john' - Why am I getting this error: Uncaught TypeError: cannot read property 'john' of undefined 为什么我收到此错误:“未捕获的TypeError:无法读取未定义的属性'标题'”? - Why am i getting this error: “Uncaught TypeError: Cannot read property 'Title' of undefined”? 为什么我收到“Select.js:1555 Uncaught TypeError:无法读取未定义的属性‘isSelectOptGroup’” - Why I am getting "Select.js:1555 Uncaught TypeError: Cannot read property 'isSelectOptGroup' of undefined" 为什么我会收到“未捕获的类型错误:无法读取未定义的属性 'body'”? - Why am I getting "Uncaught TypeError: Cannot read property 'body' of undefined"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM