2

I'm trying to make a signUp and signIn site in React, and I have added the Firebase library using npm install --save firebase
I am trying to connect my app with firebase, but I am not having much joy:

import React, { Component } from "react";
var firebase = require("firebase");
var uuid = require("uuid");

var firebaseConfig = {
  apiKey: "AIzaSyCWUBB9SgYhzOntmoJl4S7wmz6VvuyjMGA",
  authDomain: "basic-bfd76.firebaseapp.com",
  databaseURL: "https://basic-bfd76-default-rtdb.firebaseio.com",
  projectId: "basic-bfd76",
  storageBucket: "basic-bfd76.appspot.com",
  messagingSenderId: "616743515298",
  appId: "1:616743515298:web:91293dec0f3568e2b393fb",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);

class Usurvey extends Component {
  constructor(props) {
    super(props);
    this.state = {
      uid: uuid.v1(),
      studentName: "",
      answers: {
        answers1: "",
        answers2: "",
        answers3: "",
      },
      isSubmitted: false,
    };
  }
  render() {
    var studentName;
    var question;

    if (this.state.studentName === "" && this.state.isSubmitted === false) {
      studentName = (
        <div>
          <h1>Hey Student, please let us konw your name: </h1>
          <form>
            <input type="text" placeholder="Enter your name: " ref="name" />
          </form>
        </div>
      );
    }
    return (
      <div>
        <h1>Hello i'm from usurvy</h1>
      </div>
    );
  }
}
export default Usurvey;

And i get this error:

TypeError: firebase.initializeApp is not a function Module. C:/Users/alami/OneDrive/Desktop/MERN stack/Reacts project/basic/src/Usurvey.js:15 12 | appId: "1:616743515298:web:91293dec0f3568e2b393fb", 13 | }; 14 | // Initialize Firebase 15 | firebase.initializeApp(firebaseConfig); 16 | 17 | class Usurvey extends Component { 18 | constructor(props) { View compiled
error Any suggestions please?

2
  • 1
    Can you try it in the way it's mentioned in the documentation? Commented Jan 30, 2021 at 9:06
  • 1
    yes, still i get error Commented Jan 30, 2021 at 12:08

2 Answers 2

2

Documentation says that you need to call 'firebase/app' not just 'firebase'. Webpack can't find the module can't find it because of this.

const firebase = require("firebase/app");
// or import firebase from "firebase/app";

Also double check that Firebase is definitely installed in the node_modules. Check your package.json that it's 100% there as a dependency. Try re-installing it.

Sign up to request clarification or add additional context in comments.

1 Comment

Joe thanks, problem solved actually, I have some change import firebase from 'firebase' that's it.
0

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

for more info go this link

1 Comment

Thank you, I have used ES6. so, there will be import firebase from 'firebase'

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.