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

IDBIndex is not defined runtime exception in Node.js when importing ESM #6042

Closed
jamesdaniels opened this issue Mar 1, 2022 · 12 comments
Closed

Comments

@jamesdaniels
Copy link
Member

jamesdaniels commented Mar 1, 2022

[REQUIRED] Describe your environment

  • Operating System version: multi
  • Browser version: n/a (Node.js)
  • Firebase SDK version: 9.6.6 (both modular and compat)
  • Firebase Product: analytics, remote config, performance monitoring, fcm, appcheck

Including analytics, remote config, performance monitoring, FCM, or AppCheck in your server bundle while targeting ESM leads to a runtime failure IDBIndex is not defined; even if the code is not executed or guarded by platform checks / isSupported.

This is a problem as frameworks that build for the server may target ESM in Node.js. Angular for instance started doing this in 13.1+ by default.

This significantly impacts AngularFire, since we check isSupported from Analytics, RC, and Messaging in the main bundle due to how Angular's Dependency Injection operates. Apps using our library can't upgrade to the latest versions of Angular.

The root cause looks to be that the older version of the idb package (dependency of @firebase/installations) is not using the exports field in its package.json; it expects Node.js to load the CJS. Their ESM blindly expects IndexDB classes to exist. As I understand we can't simply upgrade idb (assuming they've fixed this in a recent version) since they dropped support for Internet Explorer in its entirety.

As discussed this may turn into a whack a mole situation, as this exception may just be the first of many encountered. Other packages may be setup incorrectly to support modules in Node.js. I will be exploring further.

Context

angular/angularfire#3113
angular/angularfire#3102
angular/universal#2475
nrwl/nx#8767

@jamesdaniels jamesdaniels changed the title IDBIndex is not defined runtime exception in Node.js when importing modules IDBIndex is not defined runtime exception in Node.js when importing ESM Mar 2, 2022
@puf
Copy link

puf commented Mar 8, 2022

There have also been four (so far) questions with this error on Stack Overflow in the past few days: https://stackoverflow.com/search?tab=newest&q=%5bfirebase%5d%20IDBIndex. Can we confirm whether this is an issue in the latest SDK release?

@arendjantetteroo
Copy link

arendjantetteroo commented Mar 8, 2022

@puf this started happening for us when we upgraded from firebase 9.6.7 to 9.6.8 today. For now we "fixed" it by setting 9.6.7 as our version to use.
We build in a gatsby environment, so with SSR as well.

@jamesdaniels
Copy link
Member Author

@arendjantetteroo might be a different root cause if downgrading fixed, what firebase modules are you importing?

@arendjantetteroo
Copy link

@jamesdaniels We currently only use the auth module

@actuallymentor
Copy link

Can confirm that I'm also running into this issue. The known source of this error is importing analytics on a non-web environment, but it appears to now be triggered upon import of any module.

I'm also running into this issue after downgrading, so either I am having caching issues or something changed on the backend of firebase causing the running of IDBIndex reliant code inappropriately.

@jamesdaniels
Copy link
Member Author

Thanks for chiming in. We've confirmed that this issue (and the same root cause) has spread to other products in recent releases, a fix is in play #6061.

@CarsoteCosmin
Copy link

any updates on this?

@rejhgadellaa
Copy link

@CarsoteCosmin it's live in 9.6.9: https://firebase.google.com/support/release-notes/js#version_969_-_march_17_2022

@lifeofgurpreet
Copy link

Great news!

@ReeceKenney
Copy link

Yes, I tried this morning and it's all working again. Thanks!

@ProSugu
Copy link

ProSugu commented Mar 22, 2022

Got another one after the above issue
angular/angularfire#3181

@yharaskrik
Copy link

I am also experiencing angular/angularfire#3181

If anyone has a workaround I would love to know! We had to disable our SSR for the time being.

@firebase firebase locked and limited conversation to collaborators Jul 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests