Ignore @JvmDefault when compiling to JavaScript?

Hi, trying to compile to JavaScript some code that uses the @JvmDefault annotation, the kotlinc-js compiler says:

error: unresolved reference: JvmDefault

Is there a way to ignore these annotations when compiling to JavaScript? (Except preprocessing the source files during build and removing the annotations.)


You are probably using an old version of Kotlin. The latest (since 1.3.20 if I remember correctly) version actually properly ignores those.

Strange, must be something different:

$ cat src/main/kotlin/Foo.kt 
interface Foo {

    fun getFoo() = true


$ kotlinc-js -version
info: kotlinc-js 1.3.21 (JRE 1.8.0_192-b12)

$ kotlinc-js  -output out/Foo.js -module-kind umd src/main/kotlin/Foo.kt 
src/main/kotlin/Foo.kt:3:6: error: unresolved reference: JvmDefault

You will have to import the class. It is not in the default package names. Try adding “import kotlin.jvm.JvmDefault” to the file.

Thanks for getting back. I had tried that before:

$ kotlinc-js  -output out/Foo.js -module-kind umd src/main/kotlin/Foo.kt
src/main/kotlin/Foo.kt:1:19: error: unresolved reference: JvmDefault
import kotlin.jvm.JvmDefault
src/main/kotlin/Foo.kt:5:6: error: unresolved reference: JvmDefault

I think it is because your code is not a cross-platform module. The annotation does not exist in the Javascript version, but common modules are allowed to have such annotations and then ignore them later (an unresolved expectation). In other words, to make this work you should probably bite the bullet and actually use a multiplatform project (probably with gradle), or at least include the common version of the standard library.