-3

Im new in firebase and I have not solved this problem yet, it says Uncaught TypeError: firebase.database is not a function

javascript:

 // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "AIzaSyBl6dxSW4r1k1x6-BJ7GyiIMkqMsP5zTSA",
    authDomain: "tyui-21cb8.firebaseapp.com",
    projectId: "tyui-21cb8",
    storageBucket: "tyui-21cb8.appspot.com",
    messagingSenderId: "543804913935",
    appId: "1:543804913935:web:33dd95ec68ab53b810e67a"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  console.log(firebase);

  var database = firebase.database();
  
html:

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.6.3/firebase-app.js"></script>
<script type="text/javascript" src="ske.js"></script>

<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->


</body>
</html>
SITRUUNA
  • 41
  • 3

2 Answers2

1

From your code:

 <!-- TODO: Add SDKs for Firebase products that you want to use
 https://firebase.google.com/docs/web/setup#available-libraries --> 

Which says:

Realtime Database

<script src="https://www.gstatic.com/firebasejs/8.6.2/firebase-database.js"></script>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
1

In addition to importing Firebase App (the core Firebase SDK) with

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

you need to add the imports for the Firebase products that you want to use. In your case it should be:

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

See the doc for more details.

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121