I’m trying to import the Firebase SDK in a Kotlin/JS project but I can’t find a way to import each module separately so that the whole SDK is not loaded when I only need a couple of modules from it.
I’m importing the library from Gradle like this:
and I’m using the Kotlin wrappers for it available in the following project: https://github.com/lamba92/firebase-multiplatform which seem to have been generated by Dukat and then improved by @lamba92.
When I run the app I get the following warning:
It looks like you're using the development build of the Firebase JS SDK. When deploying Firebase apps to production, it is advisable to only import the individual SDK components you intend to use. For the module builds, these are available in the following manner (replace <PACKAGE> with the name of a component - i.e. auth, database, etc): CommonJS Modules: const firebase = require('firebase/app'); require('firebase/<PACKAGE>'); ES Modules: import firebase from 'firebase/app'; import 'firebase/<PACKAGE>'; Typescript: import * as firebase from 'firebase/app'; import 'firebase/<PACKAGE>';
I have tried to change the Kotlin wrappers to only import each module like this:
@file:JsModule("firebase/app") @file:JsModule("firebase/analytics") ...
and I can call
firebase.initializeApp() which works fine, but when I try to access features like analytics like this:
val firebaseApp = firebase.initializeApp(...) firebaseApp.analytics().logEvent("test")
then I get the following error in the console at runtime:
Uncaught TypeError: firebaseApp.analytics is not a function
In this case, when I check the
app.js file generated in the
build folder I can see that the only
require() statement is for
firebase/app for some reason.
Has anyone come across this kind of issue with Firebase or any other library that has to be imported this way?