0

I've used firebase in the past for a few projects and config has been super easy. I'm experiencing issues with the new version of firebase - and keep getting a TypeError saying firebase.database() is not a function

Here are the script tags at the bottom of the body section in my HTML:

  <script src="https://www.gstatic.com/firebasejs/6.2.4/firebase-app.js"></script>
  <script src="https://code.jquery.com/jquery-3.4.1.min.js"
    integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
  <script src="assets/app.js"></script>

and my JS config looks like this:

var firebaseConfig = {
  apiKey: apiKey,
  authDomain: authDomain,
  databaseURL: dbURL,
  projectId: id,
  storageBucket: sb,
  messagingSenderId: msid,
  appId: appId
};

firebase.initializeApp(firebaseConfig);

var database = firebase.database()

The issue is not in the config because firebase.initializeApp works fine - but I cant seem to find any updates to the official docs that would explains why firebase.database() doesn't seem to work anymore.

Matt
  • 78
  • 7
  • @yoga sure it does, it explicitly says so in the docs https://firebase.google.com/docs/database/web/start - i've also used it before. Seems as if something isn't working in the newer version – Matt Jul 09 '19 at 20:07
  • sorry . my bad. this is JS – yoga Jul 09 '19 at 20:09
  • try this answer: https://stackoverflow.com/a/38250513/11460314 – yoga Jul 09 '19 at 20:11
  • @yoga figured it out, posted the answer below if you're interested – Matt Jul 09 '19 at 20:35

1 Answers1

0

Okay was able to figure this out on my own...

I only imported the basic firebase script:

<script src="https://www.gstatic.com/firebasejs/6.2.4/firebase-app.js"></script>

BUT I also needed to import the developmental firebase SDK to give me access to the realtime database functionality, hence why firebase.database() wasn't working. So I had to import a new script after the one referenced above:

<script src="https://www.gstatic.com/firebasejs/6.2.4/firebase.js"></script>

Database functions seems to be working fine now.

Matt
  • 78
  • 7