Hey everyone! Iโ€™m building a Compose Multiplatform...
# ktor
y
Hey everyone! Iโ€™m building a Compose Multiplatform app targeting android/iOS/Desktop Kotlin-Wasm. When calling REST APIs via the Ktor client in the Wasm target, Iโ€™m stuck with two errors: 1. *Original Error*`: warning: Node.js net module is not available. Please verify that you are using Node.js` (Happens when using the
CIO
engine) 2. After Removing
CIO
Engine:`Uncaught runtime errors: ERROR wasm validation error: at offset 5557696: type mismatch: expression has type (ref null 1950) but expected externref` 3. Here is my setup:
my ktor version is 3.1.0
and
compose version is 1.7.3.
Dependencies (commonMain):
Copy code
implementation(libs.ktor.client.core)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
implementation(libs.ktor.client.cio)
Koin DI Configuration:
Copy code
single {  Json { ignoreUnknownKeys = true isLenient ; = true encodeDefaults = false } }
// 2. HTTP Client Configuration 
single<HttpClient> { HttpClient(CIO) { engine { requestTimeout = 0 } 
install(ContentNegotiation) { json( json = get(), contentType = ContentType.Application.Json ) } }
here is the repository link for more context: https://github.com/yassineAbou/LLMS
a
Can you tell me what steps must be taken to reproduce the problem using your repository?
๐Ÿ™ 1
u
CIO is only for nodejs, in Wasm target you have to choose the JS client
โœ… 1
y
@Aleksei Tirman, you just need to the wasm target and that's it. I'll also send you the api key in the dms for llms ai provider.
a
To solve the problem, you can explicitly define the engine dependency for the wasmJS target: lib.versions.toml:
Copy code
ktor-client-js = { module = "io.ktor:ktor-client-js", version.ref = "ktor" }
composeApp/build.gradle.kts:
Copy code
wasmJsMain.dependencies {
    implementation(libs.ktor.client.js)
}
And remove an explicit CIO engine reference in the composeApp/src/commonMain/kotlin/org/yassineabou/playground/app/core/di/appModule.kt
โœ… 1