Search code examples
javascriptfirebasefirebase-storagefirebase-hosting

Cannot initialize Firebase Storage when deployed to Firebase Hosting


I have an app that is hosted on firebase hosting that works when running on my local server, but when I deploy it, firebase storage fails to initialize.

<script src="node_modules/firebase/firebase-app.js"></script>
<script src="node_modules/firebase/firebase-auth.js"></script>
<script src="node_modules/firebase/firebase-firestore.js"></script>
<script src="node_modules/firebase/firebase-functions.js"></script>
<script src="node_modules/firebase/firebase-storage.js"></script>
<script>
var config = {
  apiKey: "<my key>",
  authDomain: "<my domain>",
  databaseURL: "<my url>",
  projectId: "<my id>",
  storageBucket: "<my bucket>",
  messagingSenderId: "<my id>"
};
firebase.initializeApp(config);
var db = firebase.firestore();  <-- this works
var storage = firebase.storage();  <-- this doesn't
</script>

I am using the other services too without problem, and there is no differences in functionality between the deployed version and the local version except for that storage line.

when calling it from the console i get

firebase-storage.js:1 
Uncaught TypeError: Cannot read property 'path' of null
at Function.t.makeFromBucketSpec (firebase-storage.js:1)
at Function.t.extractBucket_ (firebase-storage.js:1)
at new t (firebase-storage.js:1)
at new t (firebase-storage.js:1)
at Object.storage (firebase-storage.js:1)
at t._getService (firebase-app.js:1)
at t.ur.(/anonymous function) [as storage] (<my url>/esm-bundled/node_modules/firebase/firebase-app.js:1:34079)
at Object.f [as storage] (firebase-app.js:1)
at <anonymous>:1:10

Solution

  • I was able to solve this by using the hosted version of the library

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