类型错误:firebase.storage 不是函数 [英] TypeError: firebase.storage is not a function

查看:19
本文介绍了类型错误:firebase.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();

(当我只是尝试从 存储指南 初始化存储时,链接自 firebase 的 npm 站点,我遇到了同样的错误.)

(And when I simply try to initialize storage from the storage guide, linked from firebase's npm site, I get the same error.)

在我的 Node.js 项目中,我包含以下库:

In my Node.js project, I'm including the following libraries:

  • 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.但我坚持使用 storage,并且尝试了 admin.storage().ref()firebase.storage().ref()code> 和 firebase.storage().ref("/") 具有相同的错误消息.

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.

我也试过:

var storage = firbase.storage();
var storageRef = storage.ref();

const app = firebase.initializeApp(config);
var storage = app.storage();

ref() 的无效参数 ()"/"... 但有相同的消息,但无济于事.

and with ref()'s void argument () and with "/"... but have the same message, yet to no avail.

我正在使用:

  • "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?

推荐答案

已弃用,见下文:

根据 这个答案,在 Node.js 中,google-cloud 而不是 Firebase 存储应该使用代码>包存储,似乎这个答案应该证实了这一点.代码示例:

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

那么:

const gcloud = require('google-cloud')

const storage = gcloud.storage({
    projectId: '<projectID>',
    keyFilename: 'service-account-credentials.json',
});

const bucket = storage.bucket('<projectID>.appspot.com')

截至 2018 年,这是正确答案:

或者只使用包的存储部分:

Or using only the storage part of the package:

npm install --save @google-cloud/storage

然后:

var storage = require('@google-cloud/storage')

还要检查文档 了解更多.

这篇关于类型错误:firebase.storage 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆