JS IR compiler not compatible with kotlinx.serialization?

I have a multiplatform project that compiles file but if I change one line in my gradle build file:

js(LEGACY)  { ... }

To:

js(IR) { ... }

It can’t see any of the kotlinx.serialization stuff. Errors like:

Unresolved reference: serialization (on line: import kotlinx.serialization.*)
Unresolved reference: KSerializer
etc…

A comment on this bug says serialization 1.0.0-RC is compatible with the Kotlin/JS IR compiler. I’m using an even newer version.

plugins {
  kotlin("multiplatform") version "1.4.30"
  kotlin("plugin.serialization") version "1.4.30"
  application
}
...
   val commonMain by getting {
      dependencies {       
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.1.0-RC")

I’ll just use js(LEGACY) for now.

I think there is something wrong with your Gradle cache or something. I use exactly the same plugins and I have no trouble making it work.

I just deleted ~/.gradle/caches and that didn’t solve it. Do you know if there is another cache to delete?

We are using JS-IR with Serizliazation and it is OK. If the errors you see are in the idea, it is possible that you have not synced gradle with the idea. If the error is in the console gradle build, probably something wrong with caches. Try to check gradle configuration with gradle dependencies.

I get the same errors running gradle build from command line. What am I looking for in gradle dependencies? Here is the online version (I ran gradle --scan dependencies):

https://scans.gradle.com/s/3yjv5wo5r57ko

I tracked it down by recreating my project piece by piece. It was this line in my JS gradle config:

freeCompilerArgs = listOf(...)

That = needs to be +=.

I’ve decided to retire from programming and start a hyena milk farm in Siberia.

2 Likes

Wait! Vote for KT-41985 before doing so. I’ve also mentioned your problem in KT-44958.

3 Likes

Hello!

I am running through the same issue with the following configuration.

plugins {
    kotlin("multiplatform") version "1.5.10"
    kotlin("plugin.serialization") version "1.5.10"
}

group = "me.user"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

kotlin {
    js(IR) {
        browser {
            testTask {
                useMocha()
            }
        }
    }
    sourceSets {
        all {
            languageSettings.useExperimentalAnnotation("kotlinx.serialization.ExperimentalSerializationApi")
        }

        val commonMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-protobuf:1.2.2")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jsMain by getting
        val jsTest by getting
    }
}

Using LEGACY instead just works.

Here the kind of errors it produces

Am I missing some steps?

Updating to Kotlin 1.5.20 fixes it.

The project was generated with 1.5.10 on IDEA.