Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

reactjs - _firebase_js__WEBPACK_IMPORTED_MODULE_1__.firebase.auth.GoogleAuthProvider is not a constructor

I'm trying to build authentication into my website but I've run into an issue I haven't seen anywhere else so I decided to ask it here. Web browser returns this error: _firebase_js__WEBPACK_IMPORTED_MODULE_1__.firebase.auth.GoogleAuthProvider is not a constructor.

My firebase.js file looks like this:

import fb from 'firebase/app';
require('firebase/firestore');
require('firebase/auth');
export const firebase = !fb.apps.length? fb.initializeApp({appConfig})  : fb.app();

And the file I'm doing login in looks like this:

import React from 'react';
import { Component } from 'react';
import { firebase } from './firebase.js';
class SignIn extends Component {
    state = {
        email: 'email',
        password: 'password',
    };
    db = firebase.firestore();
    auth = firebase.auth();
    SignInWithGoogle = () => {
        var provider = new firebase.auth.GoogleAuthProvider();
        this.auth.signInWithPopup(provider);
    };
    render() {
        return (
                <div>
                    <button onClick={this.SignInWithGoogle}>Google</button>
                </div>
    }
}

Thank you for your answers.

question from:https://stackoverflow.com/questions/65859669/firebase-js-webpack-imported-module-1-firebase-auth-googleauthprovider-is-no

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This solution works for me:

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

export default function firebase() {
   if(!fb.apps.length)
      fb.initializeApp(appConfig);
   }

   return fb;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...