r/Kotlin•
Chipay

Has anyone gotten ktor server wasmJs to work?

I was toying with the different ktor targets added recently, and I've gotten all of them to run without much issue, except for wasmJs, here's a minimal example:

import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.server.response.*
import io.ktor.server.routing.*

suspend fun main() {
    embeddedServer(CIO, port = 8080, host = "0.0.0.0") {
        routing {
            get("/") {
                call.respondText(text = "hello world")
            }
        }
    }.startSuspend(wait = true)
}

Running .\gradlew wasmJsNodeDevelopmentRun builds and runs flawlessly, giving the following output:

Application started in 0.003 seconds.
Responding at http://127.0.0.1:8080

So it is actually running, but going to localhost:8080 in a browser shows that the server isn't actually returning a response. This exact code works without issues on other targets. Does anyone have a clue what's going on, or if this is a known issue?

build.gradle.kts:

plugins {
    
kotlin
("multiplatform") version "2.2.20"
}
kotlin 
{
    js {
        nodejs()
        binaries.executable()
    }
    
sourceSets 
{
        
commonMain 
{
            dependencies {
                implementation("io.ktor:ktor-server-core:3.2.3")
                implementation("io.ktor:ktor-server-cio:3.2.3")
            }
        }
    }
}

Posted Sep 11, 2025, 5:14 PM UTC

15

Comments aren't archived yet

This post had 5 comments on Reddit. Comments for this period haven't been loaded into the archive yet.