Description
[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