firebase.auth is not a function

Solution 1:

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')

Solution 2:

The problem wasn't with the node_modules, it was with the way that you were importing the component.

When you export a component ES6 way, you normally do export default () => { console.log('default component export'); };

default is the keyword here, when you import a component ES6 way like import firebase from 'firebase' it's grabbing the default property from the exported object.

Keeping in mind the above example, here's what you've done wrong.

Using ES6:

import * as firebase from 'firebase'

console.log(firebase.auth) // Undefined
console.log(firebase.default.auth) // Function

Using ES5:

var firebase = require('firebase')

console.log(firebase.auth) // Undefined
console.log(firebase.default.auth) // Function

Note the .default

Solution 3:

I kept getting an error that said

"TypeError: firebase.auth is not a function"

I got the auth object to appear and the thing I did differently was install the modules in a different order.

The first time I installed the modules (this is when the auth object wasn't appearing):

// this seems to confuse things with the auth object when installed in this order
$ npm install firebase-admin --save
$ npm install firebase --save

I deleted the npm folder and started from scratch although this time I reversed the installation order:

// for some reason this worked and now I can access the auth object
$ npm install firebase --save
$ npm install firebase-admin --save

I didn't do anything else. I simply reversed the installation order by installing firebase first and firebase-admin second.

I hope this works for other people.

You can read more about it here

Solution 4:

just add >

import firebase from '@firebase/app';
require('firebase/auth');

into your project