Skip to content
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

@firebase/firestore: Firestore (6.0.4): INTERNAL UNHANDLED ERROR: configureNetworkMonitoring #1824

Closed
rauldeheer opened this issue May 26, 2019 · 26 comments · Fixed by #1870
Closed

Comments

@rauldeheer
Copy link

rauldeheer commented May 26, 2019

Environment:

  • Operating System version: Ubuntu 18.04
  • Browser version: Not relevant
  • Firebase SDK version: v6.0.4
  • Firebase Product: Firestore (database)
  • Expo version: v32.0.6

Problem description:

I'm developing a app with React Native and Expo and it has been in development since earlier this year. I started intergrating Firebase Firestore and Auth in my app right away with this package and I even have a production build in Testflight, meaning that Firebase works perfectly. I never had a problem with Firebase before.

Yesterday I changed some configuration in my app, such as the display name, some email templates and I've added a custom email domain to send emails from. I also upgraded some packages of my application, including Firebase. I've upgraded these versions:

  • firebase from "v5.11.1" to "v6.0.4".
  • react-navigation from "v3.9.1" to "v3.11.0". (Probably not relevant)

After all these changes I was still able to register and login my app, but as of today my Firestore is crashing all the time. I would like to make it clear that my firebase authentication works fine.

This is the error I'm getting, it may be different sometimes but it is always the Firestore:
IMG_2267

Steps to reproduce:

I would love to provide the steps needed to reproduce this problem, but this seems like a strange bug to me so I'm really not sure if/how you can reproduce this issue.

Relevant Code:

Please let me know what code you would like to see. I'm not sure what to post because my application always worked and I did not change any code.

More information:

You can find a post about this on Reddit which I have made here.

@wilhuff
Copy link
Contributor

wilhuff commented May 26, 2019

Your screenshot does not include the complete error. Please attach the text of the full stack trace from the console.

Firestore in Firebase 6.0.4 added support for detecting network status changes in the browser. Until we figure out what the underlying issue is, you can trivially work around this by downgrading to Firebase 6.0.3.

Note however, that I don't think react-native even supports Firebase 6 yet.

In Firestore's case there were no breaking changes between Firebase 5.x and 6, though there were breaking changes in our dependencies which is why we bumped. On the surface this doesn't seem related, but it could be.

The easiest way to get this fixed would be to put together a minimal app that shows the problem. I suspect that there's something up with our platform detection that decided this environment was a browser and tried to apply the new connectivity monitor logic when it actually won't work. However, it's not clear to me that this is the case because it's not entirely clear what you're doing: are you using expo specifically in this case or what? A sample that shows the problem will clear this up.

@rauldeheer
Copy link
Author

@wilhuff thank you for your reply.

I will create a sample as soon as I am able to and I will try to downgrade to 6.0.3 or anything under 6. My environment is React Native with Expo SDK 32 (latest at the time of writing).

I've got more reports on Reddit from people getting this problem, I will try to inform them about this. I'll tell you when I have a example which doesn't work.

@romain-faust
Copy link

I had the same problem.
Downgrading to 6.0.2 fixes the issue (I haven't tried 6.0.3).

This issue may have been introduced by #1808.

@rauldeheer
Copy link
Author

rauldeheer commented May 27, 2019

@romain-faust The issue is probably caused by that pull request, and maybe even these lines. Thank you for providing me with this information, I will try to downgrade version by version and see which one works for me.

rauldeheer pushed a commit to rauldeheer/expo that referenced this issue May 27, 2019
Add warning to the installation page to make user experience better, since this guide will make your application crash. Check [this issue](firebase/firebase-js-sdk#1824).
@schmidt-sebastian
Copy link
Contributor

@rauldeheer I believe you are correct. This issue was fixed as part of #1819. As we are already tracking this as part of #1817, I will close this issue.

Thanks for reporting this and sorry that we broke your Expo app.

@rauldeheer
Copy link
Author

@schmidt-sebastian Thank you for replying and no problem!

@fmacedoo
Copy link

Same issue here. I've already downgraded to v6.0.2 and v5.11.1 but got the same.

@wilhuff
Copy link
Contributor

wilhuff commented May 30, 2019

Hi! The configureNetworkMonitoring code did not exist prior to release 6.0.4, so if you’re still seeing this error, I strongly suspect that your downgrade may not have applied.

@yograf
Copy link

yograf commented Jun 2, 2019

Same issue here. I've already downgraded to v6.0.2 and v5.11.1 but got the same.
@fmacedoo - I got it also after down grading - try expo r -c to clear expo cache.

@rauldeheer
Copy link
Author

@wilhuff I was not able to get anything working above version 6. 5.11.1 worked right away. I cleared cache and did a lot of other things while downgrading. I will try this on a brand new project.

@mikehardy
Copy link

Saw this cross-linked while trawling through react-native-firebase.

I just did a PR to "react-native-clean-project" and if you install that package you'll now have a new react-native command react-native clean-project-auto which cleans every bit of state it can (propose a PR if it misses something!). Or you can use it more fine-grained if you like (see documentation)

Very useful if you suspect some local state is out of whack while troubleshooting module dependencies. I end up needing it a couple times a week for various reasons

This will likely be the recommended react-native way of doing this sort of deep-clean, so it might be useful information

@Almaju
Copy link

Almaju commented Jun 5, 2019

Same problem here with Expo SDK 32.
I tried to upgrade to 6.04 and downgrade to 5.11.1, to clean every piece of cache, to create a new project and copy the files... Nothing worked.
I initially did not change any code, this just started malfunctionning by its own.

@mikelehen
Copy link
Contributor

Downgrading to 5.11.1 should solve this, but if it's not, can you try upgrading to 6.1.0? That should also get you back to a working state. Else, can somebody provide a repro project that demonstrates the issue still happening? Thanks.

@fdeniz
Copy link

fdeniz commented Jun 7, 2019

Any updates? I am getting same error.
I tried from 5.11.1 to 6.1.1, cache clean & completely deleted "node_modules" folder, tried everything, nothing changed.

@QuintonC
Copy link

QuintonC commented Jun 7, 2019

6.1.0 and 6.1.1 did not work for me, but 5.11.1 did. I was on 6.0.4 previously.

@fdeniz Delete node_modules folder, remove firebase references from package.json and package-lock.json, then reinstall with npm i --save-dev firebase@5.11.1

Worked for me.

@fdeniz
Copy link

fdeniz commented Jun 7, 2019

@QuintonC Thanks, but it did not help.

As a workaround, I set "window" object to "undefined" before calling firestore until this bug fixed, sounds bad but it seems working now.
At least I can continue to develop for today.

componentDidMount() { window = undefined; let db = firebase.firestore(); ...

@mikelehen
Copy link
Contributor

@fdeniz Can you provide the exact error you are getting without that? I think there may be some confusion over what the bug was... The fix in https://github.com/firebase/firebase-js-sdk/pull/1819/files was to make sure that we don't hit the configureNetworkMonitoring() codepath if window is undefined. But in your case, window (apparently) is defined, but still something is going wrong in the configureNetworkMonitoring() code, which is unexpected. Maybe window is defined but not fully functional? Anyway, if you provide the exact error, hopefully we can figure out what is going on. Thanks.

@yannickschuchmann
Copy link

yannickschuchmann commented Jun 8, 2019

For me the issue occurred once I updated to the newest expo client app today.
Expo released Expo Web with version 33 the other day. I haven't taken a closer look but I believe they needed to introduce some kind of window object which sounds closely related with what @mikelehen said. Nice input btw :)

I checked and window is defined in my app. Going to unset it for now.
Anyone planing to use expo-web in near future? Since window seems to be not fully functional I guess the issue rather is on expo's instead of firebase' side

Two options for near future I guess:
a) Expo only sets window for web environment
b) We take care of it ourselves with something like:

import {Platform} from 'react-native'

// expo-web is inspired or based on react-native-web 
// which introduces a 'web' as platform value
if (Platform.OS !== 'web') {
  window = undefined
}

@evanb2
Copy link

evanb2 commented Jun 8, 2019

@yannickschuchmann Your solution worked perfectly without having to downgrade from v6.1.1, cheers!

@mikelehen
Copy link
Contributor

@yannickschuchmann Thanks for the added info!

Since window seems to be not fully functional I guess the issue rather is on expo's instead of firebase' side

That may be true, but it's also possible we can work around this on the Firebase side if we know exactly what's going wrong. The original report said this was happening in configureNetworkMonitoring() and the only thing we do there is attach two event listeners: https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/platform_browser/browser_connectivity_monitor.ts#L51

If that is indeed what's failing, maybe we just need to check for the existence of `window.addEventListener. Or if it's failing somewhere else now, we can look at that code instead.

So I'm still interested in seeing full error details if somebody can provide them. Thanks!

@Jncls
Copy link

Jncls commented Jun 11, 2019

@mikelehen Thanks for your help. Full error message on my machine:

@firebase/firestore:, Firestore (6.1.1): INTERNAL UNHANDLED ERROR: , configureNetworkMonitoring

[Unhandled promise rejection: TypeError: window.addEventListener is not a function. (In 'window.addEventListener('online', this.networkAvailableListener)', 'window.addEventListener' is undefined)]
- node_modules/@firebase/firestore/dist/index.cjs.js:6993:32 in configureNetworkMonitoring
- node_modules/@firebase/firestore/dist/index.cjs.js:6983:8 in BrowserConnectivityMonitor
- node_modules/@firebase/firestore/dist/index.cjs.js:7414:19 in newConnectivityMonitor
- node_modules/@firebase/firestore/dist/index.cjs.js:19046:46 in <unknown>
- node_modules/tslib/tslib.js:133:31 in step
- node_modules/tslib/tslib.js:114:61 in <unknown>
- node_modules/tslib/tslib.js:107:17 in <unknown>
- node_modules/promise/setimmediate/core.js:45:7 in tryCallTwo
- node_modules/promise/setimmediate/core.js:200:23 in doResolve
- node_modules/promise/setimmediate/core.js:66:12 in Promise
- node_modules/tslib/tslib.js:103:40 in __awaiter
- node_modules/promise/setimmediate/core.js:37:14 in tryCallOne
- node_modules/promise/setimmediate/core.js:123:25 in <unknown>
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:152:14 in _callTimer
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:200:17 in _callImmediatesPass
- node_modules/react-native/Libraries/Core/Timers/JSTimers.js:464:30 in callImmediates
* [native code]:null in callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:320:6 in 
__callImmediates
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:135:6 in <unknown>
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:297:10 in __guard
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:134:17 in flushedQueue
* [native code]:null in flushedQueue
* [native code]:null in invokeCallbackAndReturnFlushedQueue

@yannickschuchmann Your solution helps to make firestore working but unfortunately causes an error within Expo app on iOS as it tries to create a new instance of window.WebSocket (which is undefined then) in method connectToDevTools. Do you have the same problem?

@mikelehen
Copy link
Contributor

@Jncls Thanks very much! @thebrianchen submitted a fix (#1870) so that we should check for window.addEventListener before trying to call it, so once that's released you should no longer need to manually set window to undefined.

@ericjames
Copy link

Same errors for me with Expo and using firebase 6.11.1 so I downgraded to 5.11.1 and its fine.

@EKoetsjarjan
Copy link

Same here, I have also tried version 6.2.0, did not work ,downgrading to 5.11.1 did.
thank you for helping me out

@mikelehen
Copy link
Contributor

We expect this to be fixed in the next JS SDK release.

@AntelaBrais
Copy link

For me the issue occurred once I updated to the newest expo client app today.
Expo released Expo Web with version 33 the other day. I haven't taken a closer look but I believe they needed to introduce some kind of window object which sounds closely related with what @mikelehen said. Nice input btw :)

I checked and window is defined in my app. Going to unset it for now.
Anyone planing to use expo-web in near future? Since window seems to be not fully functional I guess the issue rather is on expo's instead of firebase' side

Two options for near future I guess:
a) Expo only sets window for web environment
b) We take care of it ourselves with something like:

import {Platform} from 'react-native'

// expo-web is inspired or based on react-native-web 
// which introduces a 'web' as platform value
if (Platform.OS !== 'web') {
  window = undefined
}

This worked for me too. I'm using Expo 33 and didn't need to downgrade.

@firebase firebase locked and limited conversation to collaborators Oct 10, 2019
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.