How to import Firebase SDK modules separately in Kotlin/JS?

@franco so I found this.

The thing is firebase injects the required component into the app object based on what you’ve required.

Say if you require - const messaging = require('firebase/messaging/'), the messaging() function will be available in the firebaseApp object.

So require whatever component you need before accessing.

val firebaseApp = firebase.initializeApp(...)
kotlinext.js.require("firebase/messaging") // Required to force firebase to load analytics module
firebaseApp.analytics().logEvent("test")

Sadly you’ll have to do that wherever you need analytics or you could initialize it in a singleton on startup.