Hi. I'm trying to run a Compose Multiplatform web ...
# compose-web
s
Hi. I'm trying to run a Compose Multiplatform web project, but I’m getting an error. I’m not sure what’s causing it. Can anyone help me fix this? I've attached more context below in this thread.
Copy code
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig

plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.compose.multiplatform)
    alias(libs.plugins.compose.compiler)
}

group = libs.versions.webApp.group.get()
version = libs.versions.webApp.version.get()

kotlin {
    @OptIn(ExperimentalWasmDsl::class)
    wasmJs {
        outputModuleName.set("composeApp")
        browser {
            val rootDirPath = project.rootDir.path
            val projectDirPath = project.projectDir.path
            commonWebpackConfig {
                outputFileName = "composeApp.js"
                devServer = (devServer ?: KotlinWebpackConfig.DevServer()).apply {
                    static = (static ?: mutableListOf()).apply {
                        add(rootDirPath)
                        add(projectDirPath)
                    }
                }
            }
        }
        binaries.executable()
    }

    sourceSets {
        wasmJsMain.dependencies {
            implementation(libs.compose.multiplatform.ui)
            implementation(projects.composeApp)
        }
    }
}

// Custom build directory
layout.buildDirectory.set(file(path = "$rootDir/.build/WebApp"))
This is the build script code for my web-app module.
e
Hi! What versions of libraries are you using? Maybe it's related to this issue? CMP-8765 [CMP] [WASM] "WebAssembly.instantiate(): Import #4426 "./skiko.mjs" after lifecycle-* 2.9.2
s
Hi!
Copy code
kotlin = "2.2.10"
composeMultiplatform = "1.8.2"
navigation = "2.9.0-beta05"
viewmodel = "2.9.2"
kotlinCoroutines = "1.10.2"
kotlinSerialization = "1.9.0"
koin = "4.1.0"
these are the versions that I'm using.'
e
Thank you, could you try downgrading viewmodel to
2.9.1
or bump composeMultiplatform to
1.9.0-beta03
? Will this help fix the issue on your project?
s
Sure. I changed cmp version from
1.8.2
to
1.9.0-beta3
but now I'm facing new issues in other modules for example: Caused by:
org.gradle.api.UnknownTaskException: Task with name 'wasmJsBrowserProductionWebpack' not found in project ':compose-app'.
Copy code
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.android.library)
    alias(libs.plugins.compose.multiplatform)
    alias(libs.plugins.compose.compiler)
}

group = libs.versions.composeApp.group.get()
version = libs.versions.composeApp.version.get()

kotlin {
    androidTarget()

    jvm("desktop") {
        compilerOptions {
            jvmTarget = JvmTarget.JVM_21
        }
    }

    @OptIn(ExperimentalWasmDsl::class)
    wasmJs {
        browser()
    }

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "ComposeApp"
            isStatic = true
        }
    }

    sourceSets {
        commonMain.dependencies {
            implementation(libs.bundles.koin.multiplatform)
            implementation(libs.bundles.compose.lifecycle)
            implementation(projects.shared)
            implementation(projects.userOnboarding)
        }
    }
}

compose.resources {
    generateResClass = never
}

android {
    namespace = libs.versions.composeApp.androidLibrary.namespace.get()
    compileSdk = libs.versions.composeApp.androidLibrary.compileSdk.get().toInt()

    defaultConfig {
        minSdk = libs.versions.composeApp.androidLibrary.minSdk.get().toInt()
    }
}

// Custom build directory
layout.buildDirectory.set(file(path = "$rootDir/.build/ComposeApp"))
compose-app/build.gradle.kts
for your reference.
e
What gradle task did you run? Does it work if you run it from your web-app module (not from the root directory)?
w
I had the same problem. downgrading navigation to 2.9.0-beta04 works fine