ktorio / ktorio/ktor

JS - $this$ is undefined

Open
#1,641 7 comments 0 reactions 1 assignee Claimed by @e5l View on GitHub
bug Client
Dominant language
Kotlin
Stars
14.5k
Forks
1.3k
Avg merge
2d 13h
Merged PRs (30d)
49

Description

Hi,

I'm trying out ktor with coroutines in a multiplatform project. I'm building for Android, iOS and Javascript.

For the moment my code consists of a simple get call of an api. It works fine on Android and iOS, but I'm getting an `$this$ is undefined` when my javascript calls the same code.

My gradle dependencies:

```
implementation("org.jetbrains.kotlin:kotlin-stdlib-js")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.3")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.14.0")
implementation("io.ktor:ktor-client-js:1.3.1")
implementation("io.ktor:ktor-client-core-js:1.3.1")
implementation("io.ktor:ktor-client-json:1.3.1")
implementation("io.ktor:ktor-client-serialization-js:1.3.1")
```

Here are the multiplaform JS variations:
```import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.Dispatchers

actual val uiDispatcher: CoroutineContext
get() = Dispatchers.Main

actual val defaultDispatcher: CoroutineContext
get() = Dispatchers.Default
```

```import io.ktor.client.engine.HttpClientEngine
import io.ktor.client.engine.js.Js

actual object PlatformServiceLocator {
actual val httpClientEngine: HttpClientEngine by lazy { Js.create() }
}
```

Thanks for the help

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.