TypeError: firebase.storage is not a function

uncaught typeerror: firebase.storage is not a function javascript
firebase.storage is not a function react
firebase.database is not a function 2019
typeerror: storage is not a function
firebase storage cdn
firebase-functions storage ref
firebase storage npm
upload file to firebase storage javascript

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?

DEPRECATED, see below:

According to this answer, instead of firebase storage, in Node.js, google-cloud package storage should be used, and it seems that this answer should confirm it. Code example:

npm i --save google-cloud

Then:

const gcloud = require('google-cloud')

const storage = gcloud.storage({
    projectId: '<projectID>',
    keyFilename: 'service-account-credentials.json',
});

const bucket = storage.bucket('<projectID>.appspot.com')

As of 2018, this is the correct answer:

Or using only the storage part of the package:

npm install --save @google-cloud/storage

And then:

var storage = require('@google-cloud/storage')

Also check the docs for more.

"firebase.storage is not a function" (web) · Issue #1265 · firebase , When I run the code (see below) I get the console error: Uncaught TypeError: firebase.storage is not a function . Relevant Code: Here is the  Firebase Storage is not longer used with Node.js, all documentation there is useless for Node.js. Instead use google-cloud. The references and guides for Firebase and Google Cloud do not reflect this as of today. Unlike Firebase, google-cloud costs money, even for small projects.

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

import firebase from 'firebase';
import 'firebase/storage';  // <----

firebase.initializeApp({
  ...
});
const storageRef = firebase.storage().ref();

(npm firebase v5.0.4)

[Firebase Storage] Firebase.storage is not a function. · Issue #2471 , Everything is ok except firebase storage. I have 2 "newRecord.js:53 Uncaught TypeError: firebase.storage is not a function;". I am using pure  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

"firebase.storage is not a function" (web), When I run the code (see below) I get the console error: Uncaught TypeError: firebase.storage is not a function . Relevant Code: Here is the function being called (  have to say that after updating to 5.5.2, my app stoped the firebase import saying "firebase.firestore() is not a function", just downgrading the version stops that bug. Also i tried importing via separated imports as: import firebase from 'firebase/app'; import 'firebase/firestore'; import 'firebase/auth'; import 'firebase/storage';

When using Storage with Firebase, you're correct that you can't add buckets on the free tier. However, you DO get a bucket (just one) by default. My (eventually) successful approach was to:

  1. Add Storage to my project in Firebase (NOT Google Cloud)

  2. Add the Admin SDK and set up the necessary Service Account as per the Google Docs: https://firebase.google.com/docs/admin/setup?authuser=1

  3. Add the @google-cloud/storage package as per the instructions on using the Admin SDK with storage: https://firebase.google.com/docs/storage/admin/start?authuser=1

  4. Initialize the app:

    admin.initializeApp({
      credential: admin.credential.cert("/path/to/generated/json/here.json"),
      storageBucket: "folder-URL-from-Storage-page-excluding-gs://"
    });
    
  5. Access the bucket object with (from Admin SDK docs):

    const bucket = admin.storage().bucket();

  6. Operate on the bucket with the storage library. Example:

    bucket.upload('/path/file.ext', function(err, file, apiResponse) {
      //Do Stuff
    });
    

NOTE: I spent a couple of hours convinced it wasn't working because I didn't have a bucket, but it turned out my mistake was including the gs:// in the path to my storage bucket when initializing.

Storage | JavaScript SDK, Reference for Storage. the reference with, for example path/to/image.jpg . If not passed, the returned reference points to the bucket root. Firebase Storage is not longer used with Node.js, all documentation there is useless for Node.js. Instead use google-cloud. The references and guides for Firebase and Google Cloud do not reflect this as of today. Unlike Firebase, google-cloud costs money, even for small projects.

I encounter the same problem when I test my app locally, but everything works when the project is deployed.

This way, I actually use the following workaround :

if (!firebase.storage) {
    // prevent crash when working locally
    return;
}
let ref = firebase.storage().ref()
// perform production stuff ...

It's a little bit curious, but it works in my case.

Create a Storage Reference on Web, However, your file data is stored in Google Cloud Storage, not in the Realtime Database. Create a Reference. In order to upload or download files, delete files, or  I was using firebase on android for a while and when I get to create website based on firebase realtime database and firebase storage I got error: "newRecord.js:53 Uncaught TypeError: firebase.storage is not a function;" I am using pure js, html and css and nothing else. Also unable to find any help on internet.

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();  Uncaught TypeError: firebaseApp.firestore is not a function (firebase.js @15) Steps to reproduce: yarn add firebase (with yarn v1.3.2)

Uncaught TypeError: firebase.firestore is not a function : Firebase, Uncaught TypeError: firebase.firestore is not a function include) services that you don't to use --> <script src="/__/firebase/5.8.4/firebase-storage.js"></script>. Uncaught TypeError: firebase.firestore is not a function. I am trying to make a Firestore website as part of a project for school. I'm sure I'm missing something basic, but I can't seem to get any data to save from the browser to Firestore. I am currently testing using this deployed website:

Type Error connecting Firebase Storage in Node.js, firebase.initializeApp(config);. var storageRef = firebase.storage();. It's send me : TypeError: firebase.storage is not a function. I can't understand  var x = document.getElementByID('foo'); // TypeError: document.getElementByID is not a function The correct function name is getElementByI d : var x = document.getElementById('foo');

Comments
  • Duplicate? stackoverflow.com/questions/37369466/…
  • @SergChernata No, it's a different error entirely. "Firebase is not a function. Their error was they did not initialize Firebase properly, whereas I did, and able to utilize the Firebase database and other features accordingly. Firebase Storage is the issue.
  • What do you see when inspecting the firebase.storage object? Try to do console.log(JSON.stringify(firebase.storage)). Is it undefined?
  • Yes, it's undefined; despite the JSON pointing to the correct URL, which I just double-checked.
  • Already ran into a warning...npm WARN deprecated gcloud@0.37.0: gcloud has been renamed to google-cloud. To get new features and bug fixes, you must use the new package.... So I'll post this to keep the info up-to-date... working through this now, thanks to this second answer...
  • Corrected the answer to reflect change. Thanks!
  • Just found a major unadvertised obstacle... You have to enable billing to use a bucket 😑
  • Thank you! I hope here's a way to bypass billing =\
  • How is this the right answer? It's not deprecated: firebase.google.com/docs/storage/web/start
  • Thanks for the feedback, I find that I get 'firebase' has no exported member 'storage' with firebase.storage().ref()
  • how do you authenticate a user and serve him his files during all this?
  • If you're downvoting because this isn't a good answer for you... then please refer to the very first line in my answer, which redirects users to the correct answer. I'm keeping this answer here for posterity.
  • I am getting error "TypeError: admin.storage is not a function"