【问题标题】:How to avoid Firebase warning that I’m using the development build?如何避免 Firebase 警告我正在使用开发版本?
【发布时间】:2019-01-17 01:19:10
【问题描述】:

我正在使用 firebase auth 包为我的 ReactJS 应用程序创建一个登录页面。

我已经在我的全局 firebase 文件中导入了 auth 包:

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';

const config = {
    apiKey: "xxx",
    authDomain: "xxx",
    databaseURL: "xxx",
    projectId: "xxx",
    storageBucket: "xxx",
    messagingSenderId: "xxx"
};

export default firebase.initializeApp(config);

现在在我的LoginComponent 中,我需要访问FacebookAuthProvider 类,它是firebase.auth 命名空间的一部分。 为了访问这个类,我导入了auth 命名空间。

import React, { Component } from 'react';
import { auth } from 'firebase';

class Login extends Component {
    provider = new auth.FacebookAuthProvider();

由于最后一次导入,我在控制台中收到以下警告:

It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.

For the module builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):

CommonJS Modules:
const firebase = require('firebase/app');
require('firebase/<PACKAGE>');

ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';

在浏览了这么多文档和代码之后,我仍然无法弄清楚如何在能够访问 FacebookAuthProvider 类的同时消除此警告。

第二个问题:我现在是否真的在使用完整的 firebase 开发 SDK?我只导入了auth 命名空间吧??

【问题讨论】:

    标签: typescript firebase firebase-authentication es6-modules


    【解决方案1】:

    您的登录组件正在导入完整的 Firebase SDK,这就是导致该警告的原因。您将只需要导入您需要的部分。如果已加载相同的文件,您的捆绑程序或浏览器将进行重复数据删除。

    改变这个:

    import React, { Component } from 'react';
    import { auth } from 'firebase';
    

    到这里:

    import React, { Component } from 'react';
    import firebase from 'firebase/app';
    import 'firebase/auth';
    

    【讨论】:

    • LoginComponent?所以我会有两次进口,对吧?一次在我的 firebase 配置/初始化文件和一次在我的LoginComponent?我对您的回答有些困惑,因为您还删除了导入 ReactComponent 的第一行,这是我构建组件所需要的
    • 第二位是复制/粘贴错误。感谢您的发现,我添加了它。您的登录组件现在似乎正在重新导入完整的 Firebase SDK,这就是导致该警告的原因。您将只需要导入您需要的部分。如果不必要地加载了相同的文件,您的捆绑程序或浏览器将进行重复数据删除。
    • 感谢弗兰克,您的回答很有道理。我发现我在任何地方都没有找到信息或示例这很疯狂。也许我看错了地方。无论如何,谢谢!
    • 现在我的登录组件从 firebase 包导入 firebase.auth,并使用此方法创建身份验证提供程序并进行实际身份验证。但是,不使用我在全局 firebase 配置文件 export default firebase.initializeApp(config); 中导出的已配置的 firebase 实例,这不是有点奇怪吗?
    • import firebase from 'firebase/app'; 没有默认导出。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 2023-03-06
    • 2010-10-21
    • 2019-02-21
    • 2016-12-25
    • 2021-02-04
    相关资源
    最近更新 更多