question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler Error when working with Jetpack Compose for Web

See original GitHub issue

Describe the bug When working with Serialization within the new Compose for Web library, I get a Compiler Error on trying to define Serializable data classes to interact with the public Pokemon API

To Reproduce Attach a code snippet or test data if possible.

models.kt

@Serializable
data class PokemonAPIResponse<T>(
    val count: Int,
    val next: String?,
    val previous: String?,
    val results: T
)

@Serializable
data class Pokemon(
    val id: Int,
    val name: String
)

build.gradle.kts

plugins {
    kotlin("plugin.serialization") version "1.4.32"
    kotlin("multiplatform") version "1.4.32"
    id("org.jetbrains.compose") version "0.0.0-web-dev-11"
}

group = "org.marks0mmers"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
    maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}

kotlin {
    js(IR) {
        browser()
        binaries.executable()
    }
    sourceSets {
        val jsMain by getting {
            dependencies {
                implementation(compose.web.web)
                implementation(compose.runtime)
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.2.0")
            }
        }
    }
}

Expected behavior Program to compile and be able to properly serialize these two classes

Environment

  • Kotlin version: [e.g. 1.3.30] 1.4.32
  • Library version: [e.g. 0.11.0] 1.2.0
  • Kotlin platforms: [e.g. JVM, JS, Native or their combinations] JS
  • Gradle version: [e.g. 4.10] 6.8
  • IDE version (if bug is related to the IDE) [e.g. IntellijIDEA 2019.1, Android Studio 3.4] IntelliJIDEA 2021.1.1
  • Other relevant context [e.g. OS version, JRE version, … ] Windows 10, JRE 11

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:8

github_iconTop GitHub Comments

1reaction
MrPowerGamerBRcommented, May 9, 2021

A workaround for now is creating a module without Compose that has your serializable classes, and then the Compose module without the Kotlinx Serialization plugin can depend on that module.

I haven’t tested everything yet, but it works for simple serialization/deserialization. 7wB7mttZHk

0reactions
brianguertincommented, Jul 14, 2021

Looks like this is a longstanding issue, also filed over at the compose repo: https://github.com/JetBrains/compose-jb/issues/738

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix jetpack compose compiler error? - Stack Overflow
Project does not build because of compose compiler error. Adding "androidx.compose.compiler:compiler" dependency does not fix error.
Read more >
[Solved]-Error finding jetpack compose compiler Could not ...
Coding example for the question Error finding jetpack compose compiler Could not find androidx.compose:compose-compiler:1.0.0-alpha11-kotlin.
Read more >
Quick start | Jetpack Compose - Android Developers
The Compose Kotlin compiler extension (androidx.compose.compiler) is not linked to the Compose library versions. Instead, it is linked to versions of the Kotlin ......
Read more >
What's new in Jetpack Compose - Android Developers Blog
They also shared “We rewrote the button component in our app using Compose. Before it required 800 lines of code across three files...
Read more >
Inside Jetpack Compose - Medium
Change the Composable function to be able to create a SlotTable with the Compose Kotlin Compiler Plugin. After app launch. 1. Call the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found