简体   繁体   English

反应 - 未捕获的类型错误:Class 构造函数 Firebase 不能在没有“新”的情况下调用

[英]React - Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new'

while using Firebase Auth in React I got this in the Console:在 React 中使用 Firebase Auth 时,我在控制台中得到了这个:

Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new'
    at Recompose.esm.js:803:1
    at Module../src/components/globalPages/SignUp/index.js (index.js:113:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:61:1)
    at Module../src/constants/routes.js (index.js:119:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:61:1)
    at Module../src/components/App/index.js (bundle.js:15:75)

My code:我的代码:

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import reportWebVitals from './reportWebVitals';
import App from './components/App/index';
import Firebase, {
  FirebaseContext
} from './components/Firebase';
ReactDOM.render( < React.StrictMode > < FirebaseContext.Provider value = {
  new Firebase()
} > < App / > < /FirebaseContext.Provider> </React.StrictMode > , document.getElementById('root'));
reportWebVitals();
class Firebase {
  constructor() {
    firebase.initializeApp(FirebaseConfig);
  }
  createUserWithEmailAndPassword = (email, password) => firebase.auth().createUserWithEmailAndPassword(email, password);
  signInWithEmailAndPassword = (email, password) => firebase.auth().signInWithEmailAndPassword(email, password);
  signOut = () => firebase.auth().signOut();
  passwordReset = email => firebase.auth().sendPasswordResetEmail(email);
  passwordUpdate = password => firebase.auth().currentUser.updatePassword(password);
};
export default Firebase;

const provider = firebase.auth.GoogleAuthProvider();常量提供者 = firebase.auth.GoogleAuthProvider();

The above code was giving error, Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new', In my case,上面的代码给出了错误,Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new',在我的例子中,

so this is what I did所以这就是我所做的

const provider = new firebase.auth.GoogleAuthProvider();常量提供者 = 新 firebase.auth.GoogleAuthProvider();

just add "new" keyword.只需添加“新”关键字。 It worked for me, hope this helps它对我有用,希望这有帮助

暂无
暂无

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

相关问题 未捕获的类型错误:Class 构造函数 Controller 不能在没有“new”的情况下被调用 - Uncaught TypeError: Class constructor Controller cannot be invoked without 'new' 未捕获的类型错误:类构造函数 ScratchStorage 不能在没有“new”的情况下被调用 - Uncaught TypeError: Class constructor ScratchStorage cannot be invoked without 'new' Uncaught TypeError:类构造函数Hero不能在没有“ new”的情况下调用 - Uncaught TypeError: Class constructor Hero cannot be invoked without 'new' NodeJS v15.7.0 | Electron v11.2.3 | 未捕获的错误:未捕获的类型错误:Class 构造函数<class>没有'new'就不能调用,但是?</class> - NodeJS v15.7.0 | Electron v11.2.3 | Uncaught Error: Uncaught TypeError: Class constructor <Class> cannot be invoked without 'new', but is? TypeError: Class 构造函数 MongoStore 不能在没有 'new' 的情况下被调用 - TypeError: Class constructor MongoStore cannot be invoked without 'new' TypeError: Class 构造函数 DatabaseError 不能在没有'new'的情况下被调用 - TypeError: Class constructor DatabaseError cannot be invoked without 'new' 错误TypeError:如果没有在Ionic 4中使用“ new”,则无法调用类构造函数EventEmitter - ERROR TypeError: Class constructor EventEmitter cannot be invoked without 'new' in Ionic 4 TypeError:如果没有“ new”,则无法调用类构造函数分页 - TypeError: Class constructor Pagination cannot be invoked without 'new' 类型错误:类构造函数 ESLintWebpackPlugin 不能在没有“new”的情况下被调用 - TypeError: Class constructor ESLintWebpackPlugin cannot be invoked without 'new' 类型错误:类构造函数 Wia 不能在没有“new”的情况下被调用 - TypeError: Class constructor Wia cannot be invoked without 'new'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM