1

What does it mean if you import something like this :

import 'something';

thats it. instead of using it like this :

import x from 'y'

I saw it while watching a tut on firebase; it was like this:

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

How does the last three lines work?

Srabh __
  • 29
  • 1
  • 3
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import – user3532758 Sep 27 '21 at 10:40
  • Does this answer your question? [When should I use curly braces for ES6 import?](https://stackoverflow.com/questions/36795819/when-should-i-use-curly-braces-for-es6-import) – Harun Yilmaz Sep 27 '21 at 10:45

1 Answers1

-1

The following statement imports the default export from Firebase package

import firebase from "firebase"

The other 3 are imported for their side-effects only which "runs the module's global code, but doesn't actually import any values."

If you notice you don't use import and use anything from those packages. All Firebase services are accessed using the firebase. namespace such as:

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

const auth = firebase.auth()
const firestore = firebase.firestore()

Now if you remove import "firebase/auth", the Auth SDK won't be initialize (whatever it does under the hood) and the firebase.auth() statement might throw an error that looks like:

firebase_compat_app__WEBPACK_IMPORTED_MODULE_0___default.a.auth is not a function

You can read more about imports at MDN.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84