Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase.auth is not a function

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?

like image 735
Eric Conner Avatar asked Feb 03 '18 00:02

Eric Conner


People also ask

How do I import firebase authentication?

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.

What is firebase initializeApp?

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.

What does firebase Auth return?

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.


1 Answers

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') 
like image 199
Eric Conner Avatar answered Nov 05 '22 08:11

Eric Conner