'React - Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new'
while using Firebase Auth in React I got this in the Console:
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;
Solution 1:[1]
const provider = firebase.auth.GoogleAuthProvider();
The above code was giving error, Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new', In my case,
so this is what I did
const provider = new firebase.auth.GoogleAuthProvider();
just add "new" keyword. It worked for me, hope this helps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |