TypeError: firebase.storage is not a function

前端 未结 14 1199
予麋鹿
予麋鹿 2020-11-27 14:47

Following this example, I keep getting the error:

 TypeError: firebase.storage is not a function

From this line in my code:



        
14条回答
  •  -上瘾入骨i
    2020-11-27 15:30

    I had the same problem, I had my code as following:

    import * as firebase from "firebase/app";
    import 'firebase/storage';
    
    firebase.initializeApp({
      ...
    });
    const storageRef = firebase.storage().ref();
    

    So, I found that way is only if you use Typescript.

    If you use only ES6, then you must have:

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

    If you use ES5, then you must have:

    var firebase = require("firebase/app");
    require("firebase/storage");
    
    firebase.initializeApp({
      ...
    });
    const storageRef = firebase.storage().ref();
    

    Moreover, you can also use the following way but it is not recommended because you load all services (database,auth,storage,etc):

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

    Tested with Firebase 7.15.2

提交回复
热议问题