I am using Webpack with firebase and firebase-admin.
To install firebase I ran:
npm install --save firebase
I am importing firebase using:
import * as firebase from 'firebase/app' import 'firebase/auth'
I also tried:
import * as firebase from 'firebase'
And I tried:
const firebase = require('firebase')
As suggested in web get started guide.
However, when I try to use firebase.auth()
I get an error:
console.js:32 TypeError: firebase.auth is not a function
When I use the debugger to inspect firebase
I see that it in fact does not have an auth
function:
> firebase {__esModule: true, initializeApp: ƒ, app: ƒ, Promise: ƒ, …}
How can I get auth()
included as a function using webpack?
Import firebase and firebase/authimport firebase from "firebase/app"; import "firebase/auth"; Place a FirebaseAuthProvider component at the top level of your app. ( anywhere as long as it's above the other Auth components ). Then use any of the other components anywhere in your component tree.
const app = initializeApp(firebaseConfig); A Firebase App is a container-like object that stores common configuration and shares authentication across Firebase services. After you initialize a Firebase App object in your code, you can add and start using Firebase services.
The User class is returned from any authentication state listeners, or as part of a UserCredential when using authentication methods. If you are sure the user is currently signed-in, you can also access the User via the currentUser property on the FirebaseAuth instance.
I fixed this by deleting my node_modules
directory and reinstalling everything.
Also I'm importing firebase like so:
import firebase from 'firebase' require('firebase/auth')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With