Hey <@U0BMF6PDJ>, congrats on the 1.4-m1 release. ...
# javascript
i
Hey @bashor, congrats on the 1.4-m1 release. I'm very excited to see this, in particular the typescript output. I've been using ntrrgc's tool for ts, it will be great to have full classes generated! I'm not sure if I am set up correctly, though. I'm trying to do a multiplatform project, and the release docs say to annotate your classes with @JsExport. When I use this in my common code all of my other targets fail, (jvm, ios, ...) Even when using multiplatform with just js, it fails with the same error for the compileKotlinMetadata task. Am I missing an incantation?
🙏 1
gradle.properties:
Copy code
kotlin.js.compiler=ir
build.gradle.kts:
Copy code
plugins {
  java
  kotlin("multiplatform") version "1.4-M1"
}
repositories {
   mavenCentral()
   maven("<https://dl.bintray.com/kotlin/kotlin-eap>")
   maven("<https://kotlin.bintray.com/kotlinx>")
}
val coroutinesVersion = "1.3.5-1.4-M1"
...
kotlin {
  js {
  }
  sourceSets {
    val commonMain by getting {
      dependencies {
        api("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutinesVersion")
      }
    }
    js().compilations["main"].defaultSourceSet {
      dependencies {
        api("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutinesVersion")
      }
    }
  }
}
Copy code
@ExperimentalJsExport
class MyClass() {
}
t
Do you forget
stdlib
dependencies?
i
Thanks for reaching out Victor. I haven't required this before, but I tried adding everything I could, no effect. I've tried added everything I could globally:
Copy code
dependencies {
    implementation(kotlin("stdlib"))
    implementation(kotlin("stdlib-common"))
    implementation(kotlin("stdlib-js"))
}
and to the js:
Copy code
js().compilations["main"].defaultSourceSet {
      dependencies {
        implementation(kotlin("stdlib"))
        implementation(kotlin("stdlib-common"))
        implementation(kotlin("stdlib-js"))
        api("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutinesVersion")
      }
    }
Note the Js portion works, it is the compileKotlinMetadata task that fails. Is there somewhere else I should put the dependency? My guess is that it isn't precisely the js that is failing.
t
JS target required
browser()
or
nodejs()
i
same result with js(), js {browser()}, js {nodejs()}...
t
I declare dependencies in this maner
b
You use wrong annotation, try
JsExport
i
It fails for that as well. I think the issue is that this code is in the commonMain folder, and not the jsMain folder.
here's a minimal example https://github.com/heystewart/kotlin
b
ExperimentalJsExport
needed to disable warning
The annotation is not yet available in common part
Please try in js part of multiplatform project or in pure Kotlin/JS project and let us know if it still doesn’t work for you. Thank you!
i
Yes, it does work in jsMain, but that's very limiting for a multi-platform project.
I did manage to get a .d.ts generated, and tried creating a myClass2 that extends the commonMain myClass, and noticed that it also does not recurse into the classes defined in commonMain project. I'm not sure if this aspect is logged; the generated .d.ts will therefore not have enough information to give completion in this case either.
I was able to use the workaround suggested in the above bug, however. With the added @CommonJsExport in commonMain, I get generated .d.ts, so thank you for that link! I can continue with this hack solution 😉 Thanks Victor, Zalim
👍 1
b
i
b
Thanks!