What's the recommended way to use `lazy` in common...
# multiplatform
m
What's the recommended way to use
lazy
in common code between JS and JVM? It seems to have a different definition (though for JS the type reads as
<ERROR CLASS>
on the docs)
o
Hey, you can safely use
lazy
in common code as far as I understand, you see
<ERROR CLASS>
here? It's a bug with old Dokka used to generate stdlib API reference You can open new API reference (the purple banner on top), and you will see, that it returns
Lazy<T>
on all platforms
m
When I use
lazy
I just get an unresolved reference unfortunately. The only defined sourcesets are JVM, Android and JS (IR)
Copy code
fun test() {
    val x by lazy { // Unresolved reference 'lazy'
        1
    }
}
My gradle build file:
Copy code
plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization")
    id("com.android.library")
}

repositories { ... }

kotlin {
    jvm("desktop")
    js(IR) {
        browser()
        binaries.library()
    }
    androidTarget()

    sourceSets {
        val commonMain by getting {
            // ...
        }

        val jvmMain by creating {
            dependsOn(commonMain)
        }

        val desktopMain by getting {
            dependsOn(jvmMain)
        }

        val androidMain by getting {
            dependsOn(jvmMain)
        }
    }
}

android {
    // ...
}
Using version 2.0.21 of the kotlin plugin if that matters, though able to reproduce on 2.0.0
o
can't reproduce at my side 😞
m
Looks like adding the following fixed it:
Copy code
val jsMain by getting {
    dependsOn(commonMain)

    dependencies {
        api(kotlin("stdlib-js", Versions.kotlin))
    }
}
Strange that stdlib-js isn't automatically applied
Nope, the error is back:
@Oleg Yukhnevich is there a way I can send a zip of my project privately?
Finally figured it out; apparently there was a bad kotlin-stdlib being passed through
mavenLocal
🎉 1