As part of my kotlin js project, I brought in the firebase dependency. Leveraging Dukat, I obtained access to the type references and successfully compiled them. While my Kotlin code compiles without any issues, it appears that the webpack bundle does not include the firebase library as expected.
Here's what I did :
- Installed firebase (
npm install firebase
) - Utilized Dukat to generate declarations (
).dukat firebase/app/dist/app/index.d.ts
- Copied the generated files into my Kotlin JS project.
https://i.sstatic.net/YOgjl.png
After making some modifications, my Kotlin code compiles smoothly. However, upon running the code, a
Uncaught ReferenceError: firebase is not defined error
surfaces on the frontend. This error occurs prior to the execution of any firebase-related code, indicating a potential bundling issue.
Below is the stacktrace:
sample-firebase.js:391 Uncaught Error: Cannot find module 'firebase'
at webpackMissingModule (sample-firebase.js:3)
at eval (sample-firebase.js:3)
at eval (sample-firebase.js:8)
at Object../kotlin-dce-dev/sample-firebase.js (sample-firebase.js:359)
at __webpack_require__ (sample-firebase.js:388)
at sample-firebase.js:1447
at sample-firebase.js:1450
at webpackUniversalModuleDefinition (sample-firebase.js:17)
at sample-firebase.js:18
[webpack-dev-server] Module not found: Error: Package path . is not exported from package /Users/julien/Developer/kotlin-samples/sample-firebase/build/js/node_modules/firebase (see exports field in /Users/julien/Developer/kotlin-samples/sample-firebase/build/js/node_modules/firebase/package.json)
Examining my Client code reveals that the issue arises in the line containing initializeApp
.
fun main() {
val firebaseConfig: Json = json(...)
val fire = initializeApp(firebaseConfig)
console.log(fire)
window.onload = {
console.log(sorted(arrayOf(1, 2, 3)))
startFirebase();
document.body?.sayHello() } }
The error vanishes when I remove all firebase-related code, but this also eliminates firebase functionalities.
You can access my client code here. To replicate the issue, simply run ./gradlew run
in the sample-firebase module.
I have attempted various solutions:
- Initially, Dukat was generating package names for the Kotlin declarations. Removing these changes did not impact the error.
- Directly importing firebase from my Client (`require("firebase")) failed to bundle it.
- Additionally, declaring an implementation dependency to another npm package and using homemade declarations following the instructions in the documentation proved successful.
- The runtime import issue before the javascript execution points towards a problem with the bundle.
What steps can be taken to identify the disparity between my error-free Kotlin declarations and the failed import of firebase on the frontend?