firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.82k stars 885 forks source link

Various Exports (DocumentData, FirestoreDataConverter, SnapshotOptions, User, ActionCodeSettings) missing when using v9 Modular SDK #5120

Closed sceee closed 3 years ago

sceee commented 3 years ago

[REQUIRED] Describe your environment

[REQUIRED] Describe the problem

Steps to reproduce:

After migrating to the modular v9 SDK, importing several interfaces from the new modular JS SDK fails. The compiler emits the following warnings:

export 'DocumentData' (reexported as 'DocumentData') was not found in 'firebase/firestore' (possible exports: AbstractUserDataWriter, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, FirebaseFirestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, addDoc, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, useFirestoreEmulator, waitForPendingWrites, where, writeBatch)
export 'FirestoreDataConverter' (reexported as 'FirestoreDataConverter') was not found in 'firebase/firestore' (possible exports: AbstractUserDataWriter, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, FirebaseFirestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, addDoc, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setLogLevel, snapshotEqual, startAfter, startAt, terminate, updateDoc, useFirestoreEmulator, waitForPendingWrites, where, writeBatch)
export 'SnapshotOptions' (reexported as 'SnapshotOptions') was not found in 'firebase/firestore' (possible exports: AbstractUserDataWriter, Bytes, CACHE_SIZE_UNLIMITED, CollectionReference, DocumentReference, DocumentSnapshot, FieldPath, FieldValue, FirebaseFirestore, FirestoreError, GeoPoint, LoadBundleTask, Query, QueryConstraint, QueryDocumentSnapshot, QuerySnapshot, SnapshotMetadata, Timestamp, Transaction, WriteBatch, addDoc, arrayRemove, arrayUnion, clearIndexedDbPersistence, collection, collectionGroup, deleteDoc, deleteField, disableNetwork, doc, documentId, enableIndexedDbPersistence, enableMultiTabIndexedDbPersistence, enableNetwork, endAt, endBefore, ensureFirestoreConfigured, executeWrite, getDoc, getDocFromCache, getDocFromServer, getDocs, getDocsFromCache, getDocsFromServer, getFirestore, increment, initializeFirestore, limit, limitToLast, loadBundle, namedQuery, onSnapshot, onSnapshotsInSync, orderBy, query, queryEqual, refEqual, runTransaction, serverTimestamp, setDoc, setLogLevel, snapshotEqual, startAfter, startAt, terminate, 
updateDoc, useFirestoreEmulator, waitForPendingWrites, where, writeBatch)
export 'User' (reexported as 'User') was not found in 'firebase/auth' (possible exports: ActionCodeURL, AuthCredential, EmailAuthCredential, EmailAuthProvider, FacebookAuthProvider, GithubAuthProvider, GoogleAuthProvider, OAuthCredential, OAuthProvider, PhoneAuthCredential, PhoneAuthProvider, PhoneMultiFactorGenerator, RecaptchaVerifier, SAMLAuthProvider, TwitterAuthProvider, applyActionCode, browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, checkActionCode, confirmPasswordReset, createUserWithEmailAndPassword, debugErrorMap, deleteUser, fetchSignInMethodsForEmail, getAdditionalUserInfo, getAuth, getIdToken, getIdTokenResult, getMultiFactorResolver, getRedirectResult, inMemoryPersistence, indexedDBLocalPersistence, initializeAuth, isSignInWithEmailLink, linkWithCredential, linkWithPhoneNumber, 
linkWithPopup, linkWithRedirect, multiFactor, onAuthStateChanged, onIdTokenChanged, parseActionCodeURL, prodErrorMap, reauthenticateWithCredential, reauthenticateWithPhoneNumber, reauthenticateWithPopup, reauthenticateWithRedirect, reload, sendEmailVerification, sendPasswordResetEmail, sendSignInLinkToEmail, setPersistence, signInAnonymously, signInWithCredential, signInWithCustomToken, signInWithEmailAndPassword, signInWithEmailLink, signInWithPhoneNumber, signInWithPopup, signInWithRedirect, signOut, unlink, updateCurrentUser, updateEmail, updatePassword, updatePhoneNumber, updateProfile, useAuthEmulator, useDeviceLanguage, verifyBeforeUpdateEmail, verifyPasswordResetCode)
export 'ActionCodeSettings' (reexported as 'ActionCodeSettings') was not found in 'firebase/auth' (possible exports: ActionCodeURL, AuthCredential, EmailAuthCredential, EmailAuthProvider, FacebookAuthProvider, GithubAuthProvider, GoogleAuthProvider, OAuthCredential, OAuthProvider, PhoneAuthCredential, PhoneAuthProvider, PhoneMultiFactorGenerator, RecaptchaVerifier, SAMLAuthProvider, TwitterAuthProvider, applyActionCode, 
browserLocalPersistence, browserPopupRedirectResolver, browserSessionPersistence, checkActionCode, confirmPasswordReset, createUserWithEmailAndPassword, debugErrorMap, deleteUser, fetchSignInMethodsForEmail, getAdditionalUserInfo, getAuth, getIdToken, getIdTokenResult, getMultiFactorResolver, getRedirectResult, inMemoryPersistence, indexedDBLocalPersistence, initializeAuth, isSignInWithEmailLink, linkWithCredential, linkdPassword, signInWithEmailLink, signInWithPhoneNumber, signInWithPopup, signInWithRedirect, signOut, unlink, updateCurrentUser, updateEmail, updatePassword, updatePhoneNumber, updateProfile, useAuthEmulator, useDeviceLanguage, verifyBeforeUpdateEmail, verifyPasswordResetCode)

Relevant Code:

import { FirebaseApp, initializeApp } from 'firebase/app'
import {
  DocumentData,
  SnapshotOptions,
  FirestoreDataConverter,
....
} from 'firebase/firestore'
import {
  ActionCodeSettings,
  User,
...
} from 'firebase/auth'

I do not really understand this issue as when I look at the index.d.ts, the exports are there.

looptheloop88 commented 3 years ago

Hi @sceee, thanks for the report. I tried replicating the issue, but I wasn't able to. Please try to delete the node_modules directory and the package-lock.json file, then do npm install again.

If the issue persists, please share a sample project that I can run locally to replicate the issue.

sceee commented 3 years ago

@looptheloop88 I tried deleting the node_modules directory as well as the package-lock.json but it did not help.

Here is a sample project with a build run that also emits these warnings: https://github.com/sceee/firebase-modular-reexport-demo/runs/3007852870?check_suite_focus=true#step:5:17

hsubox76 commented 3 years ago

So it looks like there are some issues with importing then exporting Typescript types due to them disappearing after transpilation. See https://stackoverflow.com/questions/40841641/cannot-import-exported-interface-export-not-found

There seem to be 3 ways around this.

  1. As mentioned in that link, for example, remove ActionCodeSettings from the main firebase/auth import list and make a separate line:

    import type { ActionCodeSettings } from `firebase/auth`

    This works in Typescript 3.8 and higher and removed the warning for that particular item for me.

  2. Another method is to import and use the type in the actual file instead of doing the import/export from a main file.

  3. I put the interfaces in a separate file (types.ts) and exported them directly, no separate import/export statements, e.g.

    
    export { DocumentData, SnapshotOptions, FirestoreDataConverter } from 'firebase/firestore'

export { ActionCodeSettings, User as BackendAuthUser } from 'firebase/auth'


The consuming files would have to import types from `types.ts` and code from `main.ts`. It might be good for organization to keep them separate, or not, depends on your preference.

Let me know if there's anything we have to change on our end but it seems at the moment like it is a Typescript issue on the consuming end.
sceee commented 3 years ago

@hsubox76 thank you for your help. Using your mentioned first method resolves the issue and works for me!