M
M
MaryChentsova2020-07-31 12:20:55
JavaScript
MaryChentsova, 2020-07-31 12:20:55

How to organize firebase imports in files?

Hello everyone: 3

Guys, such a question, but how to make it so that I can import firebase into one file and initialize it, and then transfer its functions to others if necessary? I use Webpack 4 :)

When I try to do this, I run into errors :(

In the main firebase.js file there is

import * as firebase from "firebase/app"
import "firebase/auth";
import "firebase/database";

firebase.initializeApp(config);
export var auth = firebase.auth();

And in this file, when you try, console.log(auth)everything works great! :)

But when I try to access auth from another file, I run into an error:
Failed to resolve module specifier "firebase/app" . Relative references must start with either "/", "./", or "../".

And it disappears only when I make a bundle, but in this case, each such bundle weighs about 1 mb :(

How to deal with this? Please tell me! :3

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bqio, 2020-07-31
@MaryChentsova

import * as firebase from "firebase/app"
import "firebase/auth";
import "firebase/database";

firebase.initializeApp(config);
export default firebase.auth();

import Auth from "./firebase";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question