Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase v8 Typescript definition import for User

With previous version of Firebase I use to import the Typescript definition of the User as following:

import {User} from 'firebase';

Following the introduction of v8 this import does not work anymore:

Module '"../../../../node_modules/firebase"' has no exported member 'User'. Did you mean to use 'import User from "../../../../node_modules/firebase"' instead?

The release notes points the fact that the CJS bundles was dropped, nevertheless, does not mention how this import should now be resolved.

Any help appreciated, thank you in advance.

like image 202
David Dal Busco Avatar asked Oct 27 '20 19:10

David Dal Busco


Video Answer


4 Answers

For V9.0.0(Web version 9 (modular), this can be done by

// make alias for greater readability
import { User as FirebaseUser } from "firebase/auth";

Then you can use it by:

// here direct use the type inside a hooks 
const [user, setUser] = useState<FirebaseUser | null>(null)
like image 183
ken Avatar answered Oct 27 '22 01:10

ken


You can say this instead:

import firebase from "firebase/app"
const user: firebase.User = ...

Or if you want to abbreviate it:

import firebase from "firebase/app"
type User = firebase.User
const user: User = ...
like image 43
Doug Stevenson Avatar answered Oct 26 '22 23:10

Doug Stevenson


I was able to solve my issue while importing the User with thee Firebase JS SDK v8.0.0 as following:

import {User} from '@firebase/auth-types';
like image 41
David Dal Busco Avatar answered Oct 27 '22 00:10

David Dal Busco


Have you tried importing firebase and then accessing User with firebase.User ? It's obviously way more chunky but worked for me.

Edit: I was also having issues with conflicting imports previously - where I had a file called firebase.ts that was causing my app to zoink out. Just mentioning it in case you by chance have something similar

like image 32
adrian Avatar answered Oct 27 '22 01:10

adrian