I need to generate uuid in Kotlin/JS and looking to call uuid.v4() from Kotlin/JS. I have gone through the documentation - https://kotlinlang.org/docs/using-packages-from-npm.html and https://kotlinlang.org/docs/js-modules.html but somehow cannot figure out how to invoke.
What I did is this -
- Included uuid as an npm dependency in JsMain sourceset
val jsMain by getting {
dependencies {
implementation(npm("uuid", "9.0.0"))
}
}
- In JsMain, created a uuid.kt file with this content
@JsModule("uuid")
@JsNonModule
external fun v4(options: Any?, buf: Any?, offset: Any?): String
- In Kotlin/Js code, calling
v4(null, null, null)
doesn't works.
I get this error in console -
Uncaught ReferenceError: v4 is not defined