TypeError:firebase.storage不是一个函数 [英] TypeError: firebase.storage is not a function
问题描述
TypeError:firebase.storage不是函数
从我的代码中的这一行开始:
var storageRef = firebase.storage ).REF();
(当我简单地尝试从存储指南,链接自 firebase的npm站点,我得到了同样的错误。)
在我的Node.js项目中,我包括以下库: p>
-
const firebase = require('firebase');
-
var admin = require('firebase-admin');
-
const fs = require ('fs');
至此,我已经成功读取并写入firebase数据库,用 var db = admin.database()
创建对数据库的引用,然后 var ref = db.ref( /)
...所以我知道我已经正确配置了Firebase和firebase-database。但我坚持存储
,并且已经尝试了 admin.storage()。ref()
和 firebase.storage()。ref()
和 firebase.storage()。ref(/)
错误消息。
我也试过:
var storage = firbase.storage();
var storageRef = storage.ref();
和
const app = firebase.initializeApp(config);
var storage = app.storage();
和 ref()
的void参数()
和/
...但是有相同的信息,但是没有用。 p>
我正在使用:
成功创建存储引用必须做什么?
根据这个答案,而不是firebase存储,在Node.js中, google-cloud
应该使用包存储,并且似乎这个答案应该确认它。代码示例:
npm i --save google-cloud
$ p
$ b然后:
$ p codeonst const gcloud = require('google-cloud' )
$ b $ const storage = gcloud.storage({
projectId:'< projectID>',
keyFilename:'service-account-credentials.json',
});
$ b $常量桶= storage.bucket('< projectID> .appspot.com')
或仅使用包的存储部分:
npm install --save @ google-cloud / storage
然后:
var storage = require('@ google-cloud / storage')
另外请查看文档了解更多信息。
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?
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')
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.
这篇关于TypeError:firebase.storage不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!