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.

Cannot connect to the emulators, (FirebaseError: Expected type 'Firestore$1', but it was: a custom Firestore object)

See original GitHub issue

Version info

React: 17.0.2

Firebase: 9.5.0

ReactFire: 4.2.1

Other (e.g. Node, browser, operating system) (if applicable): Node16, Chrome, MacOS

Steps to reproduce

I’m using nextjs, in the pages/_app.tsx paste the following code

import { connectAuthEmulator, getAuth } from "@firebase/auth"
import { connectFirestoreEmulator, getFirestore } from "@firebase/firestore"
import { AppProps } from "next/app"
import { AuthProvider, FirebaseAppProvider, FirestoreProvider, useFirebaseApp } from "reactfire"
import "../styles/globals.css"

export default function MyApp({ Component, pageProps }: AppProps) {
  return (
    <FirebaseAppProvider firebaseConfig={{ projectId: "shadyantra-a75f0", apiKey: "fake-key" }}>
      <FirebaseSDKProviders>
        <Component {...pageProps} />
      </FirebaseSDKProviders>
    </FirebaseAppProvider>
  )
}

function FirebaseSDKProviders({ children }) {
  const app = useFirebaseApp()
  const auth = getAuth(app)
  const firestore = getFirestore(app)

  if (true) {
    connectAuthEmulator(auth, "http://localhost:9099", { disableWarnings: true })
    connectFirestoreEmulator(firestore, "localhost", 8080)
  }

  return (
    <AuthProvider sdk={auth}>
      <FirestoreProvider sdk={firestore}>{children}</FirestoreProvider>
    </AuthProvider>
  )
}

Expected behavior

I should be able to connect to the emulator, without any error

Actual behavior

Right now it is giving me this error, “FirebaseError: Expected type ‘Firestore$1’, but it was: a custom Firestore object”

image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:12

github_iconTop GitHub Comments

4reactions
usuarezcommented, Mar 13, 2022

make sure that u’re using firebase/firestore or firebase/firestore/lite in all your firebase imports, is u’ can’t get data from db using both libs, for example if you:

import { getFirestore } from “firebase/firestore”; the need the correct imports import { deleteDoc, doc, getDoc, getDocs, onSnapshot, updateDoc } from “firebase/firestore”; but if you import { deleteDoc, doc, getDoc, getDocs, onSnapshot, updateDoc } from “firebase/firestore/lite”; the error Expected type ‘xxxx’, but it was: a custom Firestore object appears in your app.

So, use only one lib, it works for me

1reaction
jhuleattcommented, Aug 17, 2022

@usuarez’s comment https://github.com/FirebaseExtended/reactfire/issues/490#issuecomment-1066208615 about mixing firestore and firestore/lite is one possible cause.

Another is by accidentally importing two different versions of the firestore library. This is called the dual package hazard and happens when different dependencies use different versions of the same package due to bundler setup. ReactFire 4.2.2 has a new build process that should lower the chance of this happening.

Read more comments on GitHub >

github_iconTop Results From Across the Web

FirebaseError: Expected type 'Firestore$1', but it was
I am trying to run local testing for my firebase project, I'm using the admin SDK and trying to connect to the Firestore...
Read more >
firebaseerror: expected type 'ta', but it was: a custom aa object
FirebaseExtended/reactfireCannot connect to the emulators, (FirebaseError: Expected type 'Firestore$1', but it was: a custom Firestore object)#490.
Read more >
Manage indexes in Cloud Firestore - Firebase - Google
The error message includes a direct link to create the missing index in the Firebase console. Note: You can manage Cloud Firestore through...
Read more >
Adding data | Firestore - Google Cloud
There are several ways to write data to Firestore: Set the data of a document within a collection, explicitly specifying a document identifier....
Read more >
Value for argument "data" is not a valid Firestore document ...
Detected an object of type "DocumentReference" that doesn't match the expected instance. 2211 views.
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