komal deep singh chahal komal deep singh chahal - 1 year ago 247
React JSX Question

Firebase is not a constructor error(using firebase with react)

I am using firebase first time and stucked on it for 2 days. looked several example like on stackoverflow, but nothing works.

my firebase version is 3.4.2.


var Firebase = require("firebase");
var ref = new Firebase(" https://differentdatara.firebaseio.com");
var usersRef = ref.child("fish1");
alanisawesome: {
date_of_birth: "June 23, 1912",
full_name: "Alan Turing"
gracehop: {
date_of_birth: "December 9, 1906",
full_name: "Grace Hopper"


When ever i am running code it gives me "Firebase is not a constructor".

also tried with componentWillMount but nothing works.
I try like this

var Firebase = require("firebase");
this.FirebaseRef = new Firebase(" https://passwordsaves-11b33.firebaseio.com");

Answer Source

As it is written here:

In the new SDKs, you no longer instantiate a database references via new Firebase. Instead, you will initialize the SDK via firebase.initializeApp():


var ref = new Firebase("https://databaseName.firebaseio.com");


var config = {
  apiKey: "apiKey",
  authDomain: "projectId.firebaseapp.com",
  databaseURL: "https://databaseName.firebaseio.com"


var rootRef = firebase.database().ref();

Since, your firebase version is 3.4.2, you have to do it like in after section.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download