Skip to content

TypeError: e.addEventListener is not a function - Firestore (Expo) #2991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomadimitrie opened this issue Apr 26, 2020 · 11 comments · Fixed by #2994
Closed

TypeError: e.addEventListener is not a function - Firestore (Expo) #2991

tomadimitrie opened this issue Apr 26, 2020 · 11 comments · Fixed by #2994

Comments

@tomadimitrie
Copy link

[REQUIRED] Describe your environment

  • Operating System version: macOS 10.15.3
  • Browser version: - (Expo SDK 37)
  • Firebase SDK version: 7.14.2
  • Firebase Product: Firestore

[REQUIRED] Describe the problem

Running any query to Firestore throws this error:

[Unhandled promise rejection: TypeError: e.addEventListener is not a function. (In 'e.addEventListener("visibilitychange", this.ah)', 'e.addEventListener' is undefined)]

Steps to reproduce:

Initialize Firebase, then run any query.

Relevant Code:

static subscribeToAvailableRides(callback: (rides: Ride[]) => void) {
    return firebase
      .firestore()
      .collection("rides")
      .where("driver.id", "==", null)
      .onSnapshot((docs) => {
        callback(
          docs.docs.map(doc => doc.data())
        );
      });
  }
@snownoop
Copy link

Having same issue. Did not have solution right now.
There is also same topic on stackoverflow:
https://stackoverflow.com/questions/61429599/error-cloud-firestore-addeventlistener-is-not-a-function-react-native-firestor

Any ideas ?

@tomadimitrie
Copy link
Author

Having same issue. Did not have solution right now.

There is also same topic on stackoverflow:

https://stackoverflow.com/questions/61429599/error-cloud-firestore-addeventlistener-is-not-a-function-react-native-firestor

Any ideas ?

I am using Expo so I ran expo install firebase and it installed 7.9.0 and the error was gone

@schmidt-sebastian
Copy link
Contributor

@tomadimitrie Thanks for this report. We added a window. addEventListener() call that is executed when window is defined. I will add a check to only call addEventListener when it window.addEventListener exists.

@gwendall
Copy link

@tomadimitrie in the meantime, mock it by putting something like window.addEventListener = x => x at the top level of your code

@tomadimitrie
Copy link
Author

@gwendall thank you. One question, is the last version of the Firebase JS SDK fully compatible with Expo? For some reason running expo install firebase installs version 7.9.0 and I don't know whether to stick with that or upgrade to the latest version

@edi
Copy link

edi commented Apr 28, 2020

@tomadimitrie that's not something firebase contributors can answer. Look for @EvanBacon on the expo-cli repo.

Regards!

@tomadimitrie
Copy link
Author

@edi thanks!

@snownoop
Copy link

installing 7.9.0 helped me. Will check later if it can work with higher versions of firebase.
I also did cache clean, and watchman delete all. Then restart and all is working fine.

@schmidt-sebastian
Copy link
Contributor

schmidt-sebastian commented Apr 29, 2020

This will be fixed in our release next week. We are not doing any releases this week. Please either downgrade to 7.14.1 or define window.addEventListener.

@BrianGuerra2019
Copy link

I have tried several versions and none of them works, when downloading some previous version, the error disappears but the connection to firebase stops working, even with version 7.14.1

@edi
Copy link

edi commented Apr 30, 2020

This will be fixed in our release next week. We are not doing any releases this week. Please either downgrade to 7.14.1 or define window.addEventListener.

RN/Expo users will have to define global.addEventListener.

naodya added a commit to africa-covid-19-response-toolkit/diaspora-app that referenced this issue May 3, 2020
@firebase firebase locked and limited conversation to collaborators May 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants