Hi. I have been focusing on the Android target of ...
# webassembly
t
Hi. I have been focusing on the Android target of my project these past weeks, and updated some dependencies (Kotlin 2.2.0, Compose 1.9.0-alpha03, lifecycle-runtime-compose 2.9.1, Koin 4.1.0, Adaptive 1.2.0-alpha03). Now that i try to run the Wasm target, i get this error :
Copy code
[object WebAssembly.Exception]
    at handleError (<webpack://composeApp/../../node_modules/webpack-dev-server/client/overlay.js?:251:58|webpack://composeApp/../../node_modules/webpack-dev-server/client/overlay.js?:251:58>)
    at eval (<webpack://composeApp/../../node_modules/webpack-dev-server/client/overlay.js?:274:7|webpack://composeApp/../../node_modules/webpack-dev-server/client/overlay.js?:274:7>)
I have no idea about what causes this so far. The Android, JVM and JS apps work. I also use Voyager 1.1.0-beta03 and Multiplatform Settings 1.3.0. It used to run fine on Kotlin 2.1.20, Compose 1.8.1, lifecycle-runtime-compose 2.9.0-alpha05 and Koin 4.0.2-RC3.
c
Search in this channel and #C01F2HV7868. This error was discussed a couple of times already.
m
Some time ago I had the same problem. See: https://kotlinlang.slack.com/archives/C01F2HV7868/p1741011012292309 In the end it was solved by doing a simultaneous update of several libraries. You have to check the release notes of compose and pick exactly the compatible library versions for this release.
t
@Michael Paus I actually saw your thread yesterday on Google. The tab is still open. Will check for the compatible lib versions. The thing is I didn't want to go back to some previous versions.
@Chrimaeon I searched the whole internet but that channel. ๐Ÿ’€๐Ÿ˜‚
o
You can try wrapping the fun main body in a try..catch: fun main() { try { ComposeViewport(...) } catch (t: Throwable) { t.printStacktrace() throw t } } _ Make sure you have an explicit dependency on compose.ui: implementation(compose.ui) another thing could be the coroutines version. If you don't have an explicit dependency on coroutines, try to use 1.9.0 version
t
@Oleksandr Karpovich [JB] Adding an explicit dependency for compose.ui or downgrading the coroutines version to 1.9.0 version didn't change anything. But wrapping the main body in a try..catch actually helped me identify the cause. (Didn't think about doing this !!) You're a legend. Thanks to everyone. The issue was that i was trying to call these :
Copy code
private fun getUserAgent(): String {
    js("window.navigator.userAgent")
}

private fun getPlatformInfo(): String {
    js("window.navigator.platform")
}
which caused this error :
JsException: Cannot read properties of undefined (reading 'length')
TypeError: Cannot read properties of undefined (reading 'length')
Now i just need to figure out how to retrieve the info i want properly. ๐Ÿ™
o
Try returning the value:
Copy code
private fun getUserAgent(): String = js("window.navigator.userAgent")
๐Ÿ™ 1
t
Works! The difference is so slight!! Thank you very much. Claude was giving me something way too complex for this. ๐Ÿ˜‚
๐Ÿ‘ 1
๐Ÿ‘๐Ÿพ 1
m
@Oleksandr Karpovich [JB] The try/catch block seems to be a very helpful idea (although your code above wonโ€™t compile due to a typo ๐Ÿ˜‰). I am wondering though why this is not generated automatically by the wizard when you create a new project.
o
Yeah, I typed it right here without running it ๐Ÿ™‚ I think eventually there would be no need for a try..catch in the fun main. The exceptions would be less obscure. afair, it's in progress.
๐Ÿ™ 1