Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: firebase.storage is not a function

Following this example, I keep getting the error:

 TypeError: firebase.storage is not a function 

From this line in my code:

var storageRef = firebase.storage().ref(); 

(And when I simply try to initialize storage from the storage guide, linked from firebase's npm site, I get the same error.)

In my Node.js project, I'm including the following libraries:

  • const firebase = require('firebase');
  • var admin = require('firebase-admin');
  • const fs = require('fs');

Up to this point, I've successfully been able to read from and write to the firebase database, creating a reference to the database with var db = admin.database(), then var ref = db.ref("/")... So I know I've configured Firebase and firebase-database correctly. But I'm stuck on storage, and have tried both admin.storage().ref() and firebase.storage().ref(), and firebase.storage().ref("/") with the same error message.

I've also tried:

var storage = firbase.storage(); var storageRef = storage.ref(); 

and

const app = firebase.initializeApp(config); var storage = app.storage(); 

and with ref()'s void argument () and with "/"... but have the same message, yet to no avail.

I'm using:

  • "firebase": "^3.6.4"
  • "firebase-admin": "^4.0.4"
  • Node.js : v6.9.1

What must I do to successfully create a reference to storage?

like image 292
NonCreature0714 Avatar asked Dec 27 '16 20:12

NonCreature0714


People also ask

What is ref in firebase storage?

A reference can either point to a specific file or to a higher level node in the hierarchy. If you've used the Firebase Realtime Database, these paths should seem very familiar to you. However, your file data is stored in Cloud Storage, not in the Realtime Database.

How can I get download URL from Firebase storage?

Once you have a reference, you can download files from Cloud Storage by calling the getBytes() or getStream() . If you prefer to download the file with another library, you can get a download URL with getDownloadUrl() .

How do I use firebase storage in react?

Add Firebase to Reactconst storage = getStorage(app); export default storage; Use the configuration object you got after creating the Firebase project to initialize the Firebase app. The final line exports the Firebase storage reference so you can access that instance from the rest of your app.


1 Answers

I faced the same problem. In my case, I needed to include storage module besides Firebase core.

import firebase from 'firebase/app'; import 'firebase/storage';  // <----  firebase.initializeApp({   ... }); const storageRef = firebase.storage().ref(); 

(npm firebase v5.0.4)

like image 91
Ginpei Avatar answered Sep 29 '22 19:09

Ginpei