title: How do I use firebase storage from a client side React app?
body: <p>I'm trying to write a file into cloud storage from within my React app. I created a new React app using the create-react-app tool. I believe I have followed the correct instructions to get a storage reference, with code like this: <code>this.storage = firebase.storage();</code>. But, no matter how I configure firebase and no matter what I import, I see this error: <code>TypeError: _this.firebase.storage() is not a function.</code>. </p>
  
  <p>I tried importing <code>@firebase/storage</code> (commented out here) but this results in an error, and the NPM page for that module suggests this is not something a user should ever load directly.</p>
  
  <p>I believe I added the proper firebase libraries. I can use firestore and the legacy database (I removed the code to do it, but it works if I use something like <code>this.firestore = this.firebase.firestore();</code>). But, storage is unresolved.</p>
  
  <p>I'm a little unclear as to whether I should be using client libraries for cloud storage (I believe that is exactly the same thing as "storage" for Firebase). But, all the examples seem to be for accessing storage from a NodeJS app, and I want to write the file from within my browser context as client-side JavaScript.</p>
  
  <p>My package.json looks like this:</p>
  
  <pre><code>{
    "name": "my-app",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
      "@firebase/app": "^0.3.2",
      "@firebase/auth": "^0.5.2",
      "@firebase/firestore": "^0.5.6",
      "@material-ui/core": "^1.3.1",
      "@material-ui/icons": "^1.1.0",
      "enzyme": "^3.3.0",
      "enzyme-adapter-react-16": "^1.1.1",
      "react": "^16.4.1",
      "react-dom": "^16.4.1"
    },
    "scripts": {
      "start": "PORT=3009 react-scripts start",
      "build": "react-scripts build",
      "test": "react-scripts test --env=jsdom",
      "eject": "react-scripts eject"
    }
  }
  </code></pre>
  
  <p>My <code>index.js</code> looks like this:</p>
  
  <pre><code>import React, { Component } from 'react'
  import ReactDOM from 'react-dom'
  import firebase from '@firebase/app';
  import '@firebase/firestore';
  import '@firebase/auth';
  //import '@firebase/storage';                                                                                                                  
  
  var config = {
      apiKey: "ABCDEFG",
      authDomain: "abcdefg.firebaseapp.com",
      databaseURL: "https://abcdefg.firebaseio.com",
      projectId: "abcdefg",
      storageBucket: "abcdefg.appspot.com",
      messagingSenderId: "12345"
  };
  
  firebase.initializeApp(config);
  
  class Index extends Component {
  
      constructor(props) {
          super(props);
          this.state = {};
          this.firebase = firebase;
          this.firestore = this.firebase.firestore(); // This works fine.
          this.storage = this.firebase.storage(); // This fails
          console.log( "Got storage ref" );
      }
  
      render() {
          return (
              &lt;div&gt;
                  Hello
              &lt;/div&gt;
          )
      }
  }
  
  ReactDOM.render(
          &lt;Index/&gt;,
      document.getElementById('react-container')
  );
  </code></pre>
  
  <p>The firebase config is copied from the Firebase console (but changed here).</p>