question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

firebase.auth is not a function

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
PepsRyuucommented, Jul 15, 2020

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.

0reactions
PepsRyuucommented, Mar 17, 2021

Closing as the original issue was with Firebase’s documentation.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found