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.
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)
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 = ...
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';
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With