Skip to content

Usage instructions are inconsistent/conflicting/confusing #3514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Download opened this issue Jul 30, 2020 · 3 comments · Fixed by #3551
Closed

Usage instructions are inconsistent/conflicting/confusing #3514

Download opened this issue Jul 30, 2020 · 3 comments · Fixed by #3551

Comments

@Download
Copy link

Download commented Jul 30, 2020

In one place it says:

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

Note the use of the namespace @firebase.

In another place it says:

// This import loads the firebase namespace.
import firebase from 'firebase/app';
 
// These imports load individual services into the firebase namespace.
import 'firebase/auth';
import 'firebase/database';

Note how this basically all uses the same package firebase, without a namespace.

I think the first form, with @firebase is the new/preferred form or not?

Looking at the first example, it uses @firebase/app. If we open that up, we see that it points us to firebase

This package is not intended for direct usage, and should only be used via the officially supported firebase package.

...and then we come to the second example. This is confusing. Which form should I use on my new project?

All packages point to this Github Repo, which is why I am making this issue here.

EDIT

I read more docs and now I'm more confused...

It seems the docs on GCP use yet another form:

// Firebase App (the core Firebase SDK) is always required and must be listed first
import * as firebase from "firebase/app";

// If you enabled Analytics in your project, add the Firebase SDK for Analytics
import "firebase/analytics";

// Add the Firebase products that you want to use
import "firebase/auth";
import "firebase/firestore";

I don't see the namespace used here. So in that sense it looks like the second example. But this one uses import * as firebase from instead of import firebase from.

I know many big projects (e.g. Babel, Webpack) have been moving over to using namespaces/scopes. So they have been introducing the @ symbol in their package names and have been recommending their users to use the new form. Is the same true for Firebase? Is the first form actually the recommended form? And so are the second example and the docs on GCP outdated? Or is the opposite true and is the example on the Firestore package the one that is outdated? And if we need to use the non-scoped package, do we use it like import firebase from or like import * as firebase from? Please advice.

@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@Download
Copy link
Author

Thanks Google OSS Bot, but when I spend time creating an issue, I sorta expect a human to look at it...

@hsubox76
Copy link
Contributor

The first link seems to be the README for the individual @firebase/firestore package which, as it says on the page, shouldn't be directly installed by itself (it will come in as part of npm install firebase, along with the other components). I can go ahead and change the text in the README for anyone who ends up on that page.

As for import * as firebase from 'firebase/app' vs import firebase from 'firebase/app', these are both valid, we provide firebase as a default export and as a named export, for developers who need to consume it one way or the other. This question dives into the difference between them and why libraries (in this case React) often provide both: https://stackoverflow.com/questions/55285737/import-as-react-from-react-vs-import-react-from-react

I'll look into if we can settle on one of these as the "official" default suggested format and we can change either the README or the docs site so they're consistent. (I think it'll probably import firebase from 'firebase'.)

@firebase firebase locked and limited conversation to collaborators Sep 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants