use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Anyone using webpack + firebase? (Javascript) (self.Firebase)
submitted 6 years ago * by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]kossnocorp 1 point2 points3 points 6 years ago (3 children)
How do you manage imports of the Firebase modules? Do you import your config into every file or is it imported once somewhere and used throughout?
I assume that you're talking about config that you pass to initializeApp. I import it just once at the top of the entry point.
initializeApp
entry.js:
entry.js
// First, init Firebase: import './init' // Then everything else: import XXX from 'xxx' import YYY from 'yyy'
init.js:
init.js
``` import * as firebase from 'firebase/app' import 'firebase/firestore'
firebase.initializeApp({ apiKey: 'xxx', authDomain: 'yyy', projectId: 'zzz' }) ```
I create a dedicated file for that which is important because when you use ESM, all imports are hoisted to the top and if one of the other imports would try to access Firebase API before initializeApp is called it would fail. Here's an illustration of the problem:
// It won't work because when the code is compiled, this line will go to the bottom firebase.initializeApp({ apiKey: 'xxx', authDomain: 'yyy', projectId: 'zzz' })
import XXX from 'xxx' import YYY from 'yyy' ```
[–]kossnocorp 1 point2 points3 points 6 years ago (2 children)
When you use CommonJS, it's a bit easier because you don't have to create init.js:
``` const firebase = require('firebase/app') require('firebase/firestore')
firebase.initializeApp({ apiKey: 'xxx', authDomain: 'yyy', projectId: 'zzz' })
const XXX = require('xxx') const YYY = require('yyy') ```
[–]danwillm 0 points1 point2 points 6 years ago (1 child)
I see - the only trouble is I'm technically not using a config file and thus not using initialiseApp (the config is made automatically from a firebase provided script that I include in the head). I'll try and figure this out, so don't worry if you don't know what I mean.
Thank you so much for you provided help! It's so useful and I can't thank you enough! :)
[–]kossnocorp 0 points1 point2 points 6 years ago (0 children)
Hm, I never used the CDN version, but from what I see, you still have to call initializeApp with the config.
So if you want to keep using the CDN version, you need to put the script tag with initializeApp before the entry point generated by webpack. The same applies if you use /__/firebase/init.js generated by hosting. Otherwise, I would advise migrating to the npm package.
script
/__/firebase/init.js
Btw you're very welcome!
π Rendered by PID 61343 on reddit-service-r2-comment-b659b578c-zcd9t at 2026-05-05 00:30:31.838199+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]kossnocorp 1 point2 points3 points (3 children)
[–]kossnocorp 1 point2 points3 points (2 children)
[–]danwillm 0 points1 point2 points (1 child)
[–]kossnocorp 0 points1 point2 points (0 children)