Getting the error : Module not found: Can't resolve 'firebase/app'

Viewed 8034
import 'firebase/auth';
import 'firebase/database';
import 'firebase/storage';



var firebaseConfig = {
    apiKey: "AIzaSyCEtbuZ3oIA8amHdyOBXMLLmHCZMuHIPVg",
    authDomain: "react-slack-clone-6284c.firebaseapp.com",
    databaseURL: "https://react-slack-clone-6284c.firebaseio.com",
    projectId: "react-slack-clone-6284c",
    storageBucket: "react-slack-clone-6284c.appspot.com",
    messagingSenderId: "1010926924701",
    appId: "1:1010926924701:web:d5d331af0cfe6fd31db574",
    measurementId: "G-9K7S58J5LF"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();

  export default firebase;

My firebase.js file is inside the src folder and i am getting the error as mentioned.While importing firebase to my Register.js, i am encoutering this error

2 Answers

See https://firebase.google.com/docs/web/setup#using-module-bundlers

You should add import * as firebase from "firebase/app";

// Firebase App (the core Firebase SDK) is always required and must be listed first
import * as firebase from "firebase/app";

// If you enabled Analytics in your project, add the Firebase SDK for Analytics
import "firebase/analytics";

// Add the Firebase products that you want to use
import "firebase/auth";
import "firebase/firestore";

// TODO: Replace the following with your app's Firebase project configuration
const firebaseConfig = {
  // ...
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);

npm install firebase@8.3.1 --save

Related