Uncaught ReferenceError: initializeApp is not defined

1,918 views
Skip to first unread message

Aayushi Somani

unread,
Jun 2, 2020, 10:20:00 AM6/2/20
to Firebase Google Group
I'm trying to connect a contact us form on my web app to firebase. It wouldn't connect and gives out this error: Uncaught ReferenceError: initializeApp is not defined

I have put these scripts in my <head> tag: 

<!--<script src="home1.js"></script>-->
<script type="module" src="contact.js"></script>
<!--<script src="presentation.js"></script>-->

<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-app.js"></script>

<!-- If you enabled Analytics in your project, add the Firebase SDK for Analytics -->
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-analytics.js"></script>

<!-- Add Firebase products that you want to use -->
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.14.5/firebase-database.js"></script>



Please help!

Kato Richardson

unread,
Jun 2, 2020, 11:47:47 AM6/2/20
to Firebase Google Group
Aayushi,

The order of the scripts matters. Try moving contact.js to the bottom of that list and you should be fine. (Presumable the call to initializeApp() is inside that file).

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/3f70d683-6736-461d-bbb9-8730a88e73d1%40googlegroups.com.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Aayushi Somani

unread,
Jun 2, 2020, 12:32:23 PM6/2/20
to Firebase Google Group
Hi,

Thanks, the reference error is gone but it still won't push any data to the database, I'm sharing the code snippet for contact.js: 
// Initialize Firebase
function initializeApp() {

   
var firebaseConfig = {
       
apiKey: "AIzaSyBlKtHSHez53zdskf6LqZ4GyljzBk5Dq6G95oM",
        authDomain: "white-web-cac.firebaseapp.com",
        databaseURL: "https://white-web-cac.firebaseio.com",
        projectId: "white-web-cac",
        storageBucket: "white-web-cac.appspot.com",
        messagingSenderId: "168259507sdc672",
        appId: "1:168259507672:web:f352b0c6682dsf806d7904ead",
        measurementId: "G-KXTSR3473457V"
    };
// Initialize Firebase

    firebase.initializeApp(firebaseConfig);
    firebase.analytics();


// Reference messages collection
    var messagesRef = firestore.database().ref('messages');

// Listen for form submit
    document.getElementById('ContactFormData').addEventListener('submit', submitForm);
    //const db = firestore.collection("ContactFormData");

// Submit form
    function submitForm(e) {
        e
.preventDefault();

        //Get value
        let name = getInputVal('name');
        let company = getInputVal('company');
        let email = getInputVal('email');
        let phone = getInputVal('phone')
       
let message = getInputVal('message');

        // Save message
        saveMessage(name, company, email, phone, message);


        // Show alert
        document.querySelector('.alert').style.display = 'block';

        // Hide alert after 3 seconds
        setTimeout(function () {
           
document.querySelector('.alert').style.display = 'none';
        }, 3000);

        // Clear form
        document.getElementById('contactForm').reset();
    }

// Function to get form value
    function getInputVal(id) {
       
return document.getElementById(id).value;
    }


// Save message to firebase
    function saveMessage(name, company, email, phone, message) {
       
var newMessageRef = messagesRef.push();
        newMessageRef.set({
           
name: name,
            company: company,
            email: email,
            phone: phone,
            message: message
       
});
    }
}
Reply all
Reply to author
Forward
0 new messages