Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: It looks like you're using the development build of the Firebase JS SDK

I've integrated Firebase into my React.js app as such: https://firebase.google.com/docs/database/web/start

fire.js:
import firebase from 'firebase'  var config = {   apiKey: "####",   authDomain: "#",   databaseURL: "#",   projectId: "#",   storageBucket: "#",   messagingSenderId: "#" }; var fire = firebase.initializeApp(config); export default fire; 
App.js:
import fire from './fire';  class App extends Component {     componentWillMount(){         let messagesRef = fire.database().ref('messages').orderByKey().limitToLast(100);     } } 

But now I'm getting this warning in the console:

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 with the name of a component - i.e. auth, database, etc):

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

ES Modules: import firebase from 'firebase/app'; import 'firebase/';

How do I fix this warning?

I have tried (in fire.js) changing this:

import firebase from 'firebase' 

To this:

import firebase from 'firebase/app' 

That results in this error: enter image description here

like image 351
etayluz Avatar asked Jun 05 '18 19:06

etayluz


People also ask

What is firebase JavaScript SDK?

Firebase is an app development platform that provides integrated tools to help you build, grow and monetize your apps. The Firebase SDK enables access to the Firebase services in an intuitive and idiomatic manner on several platforms.

What is firebase SDK?

Firebase supports SDKs for Android, IOS, and Web. Combined with Firebase security rules and Firebase Auth, the mobile and web SDKs support serverless app architectures where clients connect directly to your Firebase database.

Does firebase support JavaScript?

The Firebase JavaScript SDK is built on the latest standards of the web platform. Some older browsers and JavaScript environments do not support all the features required by Firebase. If you must support these browsers/environments, then you need to load polyfills accordingly.


2 Answers

The proper way to import firebase is as such:

import firebase from 'firebase/app'; import 'firebase/database'; // If using Firebase database import 'firebase/storage';  // If using Firebase storage 
like image 170
etayluz Avatar answered Sep 20 '22 09:09

etayluz


The proper way to import firebase and getting rid of the warnings is:

Always import this way

import firebase from 'firebase/app'; 

Then import each sub-modules (each firebase service) as needed

import 'firebase/auth';        // for authentication import 'firebase/storage';     // for storage import 'firebase/database';    // for realtime database import 'firebase/firestore';   // for cloud firestore import 'firebase/messaging';   // for cloud messaging import 'firebase/functions';   // for cloud functions 
like image 45
Yash Chavda Avatar answered Sep 21 '22 09:09

Yash Chavda