https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

rivu.chakraborty

11/15/2023, 10:22 AM
We're using KMP (Android, iOS, tvos and js-IR) for internal SDKs. It's working fine in all platforms except JS. In JS as well, the SDKs are working fine in standalone, however when 2 KMP SDKs are integrated together in the web app we're getting the below error.
Copy code
TypeError: ioDispatcher(.. .plus_rgw9wi_ ks is not a function
Code:
Copy code
fun ioDispatcher() = Dispatchers.Default
//---------------------------
val job = Job()
val scope = CoroutineScope(ioDispatcher() + job)
We believe it's because while transpiling the Kotlin compiler is renaming the methods and they're different for the SDKs and one SDK is trying to resolve it from another. Without making a monorepo and co-building both the SDKs, is there any other way to share a common kotlin-js dependency or avoid the above error? CC @Sebastian Aigner @Arnav Gupta
s

Sebastian Aigner

11/15/2023, 1:45 PM
I haven't seen this specific error, but @anton.bannykh, maybe you're aware of something here? 🤔
r

rivu.chakraborty

11/15/2023, 2:14 PM
Best solution would be if we can bundle the kotlin-js and Coroutines dependencies separately, as we're using KMP for multiple SDKs, having a common dependency would solve the problem as well as will reduce the size of individual SDKs
a

anton.bannykh

11/15/2023, 2:16 PM
We believe it's because while transpiling the Kotlin compiler is renaming the methods and they're different for the SDKs and one SDK is trying to resolve it from another.
Most probably that's the cause.
Without making a monorepo and co-building both the SDKs, is there any other way to share a common kotlin-js dependency or avoid the above error?
As you've mentioned, we would suggest to build all the
.js
code together at once so that all the names match. Otherwise it's kinda tricky. What you could do is mark the common library API with
@JsExport
. This way you'll force the compiler to use the non-mangled names, which will of course be stable.
r

rivu.chakraborty

11/15/2023, 2:18 PM
We used
@JSExport
for all functions and classes that's supposed to be called from js directly, should we do that for the functions we call from jsMain as well?
a

anton.bannykh

11/15/2023, 2:20 PM
If you want to reuse this module across different project - then this could be the way. Unfortunately we don't have an official support for that yet.
r

rivu.chakraborty

11/15/2023, 2:23 PM
Got it, thanks for the support. Should I raise a youtrack request for this support or Kotlin team completely abandoned Kotlin/JS?
a

anton.bannykh

11/15/2023, 2:23 PM
Sure)
r

rivu.chakraborty

11/15/2023, 2:24 PM
Thanks so much 🙏 Really appreciate the prompt response and the help
👌🏼 1
a

andylamax

11/16/2023, 3:51 AM
I can confirm I did encouter this exact problem. i had to compile them together (under a single umbrella module) to work around this issue
5 Views