I have a simple wasmjs demo app, which was working...
# webassembly
s
I have a simple wasmjs demo app, which was working fine until i upgraded to latest kotlinx-coroutine 1.8.0. After that, it throws the following error.
Copy code
Uncaught (in promise) TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.
The application is being served from a ktor app using static resource directory. Any idea how to debug/fix this issue ?
Things were working fine until 1.8.0-RC release of kotlinx-coroutine. I am still not 100% sure the coroutine update causing this error.
a
What server do you use for serving static files?
s
ktor, the wasm module compiled output will get copied to backend module resources/app directory and will get served as static resources
Copy code
fun Route.webApp() {
  webApp("/app", "app")
}

fun Route.webApp(remotePath: String, basePackage: String) {
  staticResources(remotePath, basePackage) {
    exclude { it.path.endsWith(".log") }
    default("index.html")
    modify { url, call ->
      when (call.request.path()) {
        remotePath -> call.respondRedirect("$remotePath/")
      }
    }
  }
}
The same issue when hosting the wasmJsBrowserDistribution on github pages also.
a
Could you check what is Content-Type of the response with the `wasm`file?
s
hmm..somehow it shows as
Content-Type: text/html; charset=UTF-8
what should be actual content type for wasm files?
by thw way, the typs is
fetch
for this wasm file as it’s loaded by the wrapper script.
a
Should be
application/wasm
Could you make something like this:
Copy code
if (call.requrest.path().endsWith(".wasm")) {
   call.response.header(HttpHeaders.ContentType, "application/wasm")
}
s
ok..let me check that
Seems like the issue is something different… Any idea why .wasm files not getting copied to dist directory ? I am running
wasmJsBrowserDistribution
seems like a regression on
2.0.0-Beta4
Can be easily reproduce by running
Copy code
$ git clone <https://github.com/Kotlin/kotlin-wasm-examples>
$ cd browser-example 
// change the plugin version to 2.0.0-Beta4
$ ./gradlew wasmJsBrowserDistribution
a
@Ilya Goncharov [JB] ^^