suresh
01/02/2024, 8:28 PMasync module:63 Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #2 module="js_code" function="kotlin.wasm.internal.stringLength": function import requires a callable
- Has anybody seen this error before?ephemient
01/02/2024, 8:34 PMephemient
01/02/2024, 8:36 PMbuild/dist/wasmJs/productionLibrary
, project-name-wasm-js.wasm
should be accompanied by project-name-wasm-js.uninstantiated.mjs
and `project-name-wasm-js.mjs`; the last one sets everything upsuresh
01/02/2024, 8:48 PMthat should be set up by the wrapper that Kotlin generates.yes, i check the dist (
wasmJsBrowserDistribution
) output and everything seems ok.. i am trying to do some js interop by importing
import kotlinx.browser.document
import kotlinx.browser.window
import org.w3c.dom.*
import org.w3c.dom.events.Event
Simple hello world is working fine thoughephemient
01/02/2024, 9:18 PMsuresh
01/02/2024, 10:33 PMval WasmCompileError: JsAny = js("WebAssembly.CompileError")
fun main() {
println("Hello, Kotlin Wasm!")
window.addEventListener("error") {
it as ErrorEvent
unhandledError(it, it.error!!)
}
window.addEventListener("unhandledrejection") {
it as PromiseRejectionEvent
unhandledError(it, it.reason!!)
}
}
fun unhandledError(event: Event, error: JsAny) {
if (error::class == WasmCompileError) {
val warn = document.getElementById("warning") as HTMLDivElement
warn.style.display = "initial"
// Hide a Scary Webpack Overlay which is less informative in this case.
val webPack = document.getElementById("webpack-dev-server-client-overlay") as? HTMLDivElement
webPack?.style?.display = "none"
}
}
Everything else is sameephemient
01/02/2024, 10:41 PMsuresh
01/02/2024, 10:42 PMsuresh
01/03/2024, 7:17 AMapplyBinaryen()
. Disabled it and seems fine now.Svyatoslav Kuzmich [JB]
01/03/2024, 8:40 AMWebAssembly.CompileError
is thrown by compiling Kotlin .wasm
module, then your Kotlin code will not be runnable, and you will not be able to handle the error in Kotlin. Or are you compiling some other WebAssembly and handling it in Kotlin?suresh
01/03/2024, 8:43 AMSvyatoslav Kuzmich [JB]
01/03/2024, 8:49 AM