firebase.auth is not a function
See original GitHub issueI’m using Firebase in a project. I believe there is some issue when using nollup and the firebase imports: import 'firebase/auth'
and import 'firebase/analytics'
. When I run the following with nollup I get the error:
Uncaught (in promise) TypeError: firebase.auth is not a function
<script lang='ts'>
import { onMount } from 'svelte'
import * as firebase from 'firebase/app'
import 'firebase/auth'
import 'firebase/analytics'
import { Authorization } from '@state'
import { authInitialized } from './utils'
const config = {
...
}
onMount(async () => {
firebase.initializeApp(config)
$authInitialized = true
firebase.auth().onAuthStateChanged(function(user) {
firebase.analytics()
let idToken
if (user) {
idToken = user.getIdToken.toString()
}
$Authorization = idToken ? `Bearer ${idToken}` : null
});
})
</script>
However, when I run using plain rollup, I do not get this error. Any ideas?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
firebase.auth is not a function - Stack Overflow
1 with firebase-admin 6.0.0 in my package.json. npm update firebase upgraded me to 5.5.4 and the firebase.auth() is not a function problem ...
Read more >firebase.firebase.auth is not a function · Issue #5930 - GitHub
I noticed that you've not imported the auth function properly. Since you are using v9, you have 2 options on how to import...
Read more >Auth | JavaScript SDK | Firebase JavaScript API reference
Reference for Auth. ... and complete the link. auth/auth-domain-config-required: Thrown if authDomain configuration is not provided when calling firebase.
Read more >app_1.default.auth is not a function ... all of a sudden? - Reddit
The main problem here seems to be the lack of a "default" export from firebase, requiring you to import it like import *...
Read more >Stuck with Firebase Auth - RedwoodJS Community
So after creating an app at Firebase and adding it as auth provider in Redwood app, ... initializeApp is not a function (anonymous...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Upon further digging, this seems to be some weird documentation / TypeScript problem with Firebase:
https://github.com/firebase/firebase-js-sdk/issues/3315#issuecomment-653872699 https://github.com/firebase/firebase-js-sdk/issues/1832 https://github.com/firebase/firebase-js-sdk/issues/1008#issuecomment-405219175
Not entirely sure what’s going on, but it sounds like their documentation assumes you’re using TypeScript, and that TypeScript has a different behaviour for resolving namespace imports. I think TypeScript has a flag that allows the namespace import to work even though it’s a default export. Very weird and goes against the ESM spec.
Closing as the original issue was with Firebase’s documentation.