1

I'm trying to add firebase realtime database to my website, but when i use firebase.database(); i get the following error:

btncnt.js:44 Uncaught TypeError: firebase.database is not a function

This is my code:

    var Config = {
        apiKey: "********************",
        authDomain: "**********.firebaseapp.com",
        databaseURL: "https://*************",
        projectId: "***********",
        storageBucket: "**********",
        messagingSenderId: "**************",
        appId: "************"
    };
    // Initialize Firebase
    firebase.initializeApp(Config);
    console.log(firebase);
    var database = firebase.database();

Why is firebase.database not a function?

2
  • 1
    You have to include the firebase core <script src="/__/firebase/6.3.4/firebase-app.js"></script> and firebase database <script src="/__/firebase/6.3.4/firebase-database.js"></script>, if you want to you firebase.database();. You can also include the entire SDK like this: <script src="/__/firebase/6.3.4/firebase.js"></script>. See this section by firebase. Commented Aug 4, 2019 at 12:25
  • 1
    @Minding That sounds like an answer to me. :) Commented Aug 4, 2019 at 13:50

1 Answer 1

3

You have to include the firebase core

<script src="/__/firebase/6.3.4/firebase-app.js"></script>

...and firebase database

<script src="/__/firebase/6.3.4/firebase-database.js"></script>

...if you want to use firebase.database();.

You can also include the entire SDK like this:

<script src="/__/firebase/6.3.4/firebase.js"></script>

See this firebase article for more information.

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

Comments

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.