Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase.initializeApp is not a function

I'm trying to make a site in React, and I have added the Firebase library using npm i firebase --save

I am then trying to call this in my app, but I am not having much joy:

import * as firebase from "firebase";

const instance = firebase.initializeApp({
  apiKey: '123',
  authDomain: 'https://123.firebaseapp.com/',
  databaseURL: 'https://123.firebaseio.com/'
});

export default instance;

No matter what I try, it throws:

firebase.initializeApp is not a function

I've checked its in my node_modules and i've reinstalled it, but I still have no such luck.

Any suggestions?

like image 646
K20GH Avatar asked Feb 07 '17 12:02

K20GH


People also ask

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.

How do I initialize Firebase app in react native?

Creating and configuring a firebase projectHead over to Firebase console and add a new Firebase project, name it React Native Todo App . Once the project is set and ready, click Continue. You will be redirected to the console of that newly created project. React Native is cross-platform.

How to add Firebase to react project?

To integrate Firebase into our React app, we need to first get the web configuration object and then use it to initialize Firebase in our react app. Copy the config to the clipboard; we'll need it later on to initialize Firebase. Then, click Continue to console to complete the process.

What is Firebase js?

Firebase is a Backend-as-a-Service (BaaS) app development platform that provides hosted backend services such as realtime database, cloud storage, authentication, crash reporting, analytics, and so on. It is built on Google's infrastructure and scales automatically.


2 Answers

I had a the same problem with firestore in my Vue application.

I eventually came right by doing the following in my firebase.js file:

import { firebase } from '@firebase/app'

As opposed to :

import * as firebase from 'firebase/app'

Also if you are using any specific firebase modules you need to import them individually like so:

import '@firebase/auth'
import '@firebase/firestore'

const db = firebase.firestore()
const auth = firebase.auth()

export { db, auth }

Hope this helps somebody.

like image 146
Austin Reid Avatar answered Oct 31 '22 02:10

Austin Reid


Can you please try with:

var firebase = require('firebase/app');

Credits.

like image 39
Jordan Enev Avatar answered Oct 31 '22 01:10

Jordan Enev