0

I did a research but found that problem only in node.js context, or react context but from a long time ago, and guys say that upgrading their firebase helped. Mine was installed just last month.

Basically I'm using React with firebase api, and I this code:

firebase.auth().signInWithEmailAndPassword('an email', 'a password);

Throws the following error: TypeError: WEBPACK_IMPORTED_MODULE_2__firebase.a.auth is not a function

Of course I'm importing firebase:

import firebase from '../../firebase';

All the other firebase commands work just fine.

Has anyone had an experience with that problem using react.js ?

Thanks a lot in advance

2
  • Double check whether the path is correct. Also what are you exporting from that file? Share Firebase file code for better assistance Commented Nov 10, 2018 at 4:34
  • 1
    Hey mate thanks I was stupid not to use import "firebase/auth" in the firebase file. Thanks a lot you really helped me Commented Nov 10, 2018 at 23:37

3 Answers 3

1

Just posting the answer, maybe to help others. The simple solution (thanks to think-twice) is to import "firebase/auth". Here is an example of the Firebase file:

import firebase from 'firebase/app';
import 'firebase/storage';
import "firebase/database";
import "firebase/auth"


 // Initialize Firebase
 var config = {
    apiKey: "*********************",
    authDomain: "...",
    databaseURL: "...",
    projectId: "....",
    storageBucket: "....",
    messagingSenderId: "..."
  };
  firebase.initializeApp(config);

  const storage = firebase.storage();

  export {
      storage, firebase as default
  }
Sign up to request clarification or add additional context in comments.

Comments

0

First check your path is correct, if is, try to delete the node_modules folder and make npm install again !

Comments

0

in the newer version of firebase you have functions to get firestore, storage or realtime database

import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getAuth } from "firebase/auth";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  // your firebase configuration
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
export const firestore = getFirestore(app); //use this for firestore
export const storage = getStorage(app); // use this for storage 
export const auth = getAuth(app);
export default app;


Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.