我有一个在firebase托管上托管的应用程序,该应用程序在本地服务器上运行时可以运行,但是当我部署它时,firebase存储无法初始化。
<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>
我也正在使用其他服务,没有问题,除了该存储行,已部署版本和本地版本在功能上没有区别。
从控制台调用它时,我得到
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
答案 0 :(得分:0)
我能够通过使用库的托管版本来解决此问题
<script src="https://www.gstatic.com/firebasejs/5.2.0/firebase-storage.js"></script>