Daniele B
07/12/2023, 5:33 AMjsBrowserRun
, the browser shows a blank page and the console shows this error:
Uncaught Error: Error loading module 'cms'. Its dependency 'androidx-runtime' was not found. Please, check whether 'androidx-runtime' is loaded prior to 'cms'.
at cms.js:8:13
at cms.js:21:2
Using Kotlin 1.8.20 and Compose Multiplatform 1.4.1
Any idea?Daniele B
07/12/2023, 5:35 AMplugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("com.android.library")
id("org.jetbrains.compose")
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.3")
}
kotlin {
android ()
jvm("desktop") {
compilations.all {
kotlinOptions.jvmTarget = "18"
}
}
js(IR) {
browser()
}
sourceSets {
val commonMain by getting {
dependencies {
api(compose.foundation)
api(compose.ui)
api(compose.material)
api(compose.runtime)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
api(compose.components.resources)
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.2")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("io.ktor:ktor-client-core:"+extra["ktor.version"])
implementation("io.ktor:ktor-client-logging:"+extra["ktor.version"])
implementation("io.ktor:ktor-client-content-negotiation:"+extra["ktor.version"])
implementation("io.ktor:ktor-client-auth:"+extra["ktor.version"])
implementation("io.ktor:ktor-serialization-kotlinx-json:"+extra["ktor.version"])
implementation("com.russhwolf:multiplatform-settings-no-arg:"+extra["multiplatformSettings.version"])
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation("com.russhwolf:multiplatform-settings-test:"+extra["multiplatformSettings.version"])
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-okhttp:"+extra["ktor.version"])
}
}
val androidUnitTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
}
}
val desktopMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.7.2")
implementation("io.ktor:ktor-client-apache:"+extra["ktor.version"])
implementation("ch.qos.logback:logback-classic:1.4.7")
}
}
val desktopTest by getting
val jsMain by getting {
dependencies {
implementation(compose.html.core)
implementation("io.ktor:ktor-client-js:"+extra["ktor.version"])
}
}
val jsTest by getting
}
}
android {
namespace = "eu.baroncelli.dkmpsample.shared"
compileSdk = extra["android.compileSdk"].toString().toInt()
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
compileOptions {
sourceCompatibility = JavaVersion.VERSION_18
targetCompatibility = JavaVersion.VERSION_18
isCoreLibraryDesugaringEnabled = true
}
defaultConfig {
minSdk = extra["android.minSdk"].toString().toInt()
}
buildTypes {
getByName("release") {
isMinifyEnabled = true
}
}
}
Daniele B
07/12/2023, 5:36 AMplugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}
kotlin {
js(IR) {
moduleName = "cms"
browser()
binaries.executable()
}
sourceSets {
val jsMain by getting {
dependencies {
implementation(project(":shared"))
}
}
}
}
compose.experimental {
web.application {}
}
repositories {
mavenCentral()
}
Daniele B
07/12/2023, 5:36 AM<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="skiko.js"></script>
<title></title>
</head>
<body>
<canvas id="ComposeTarget" width="1" height="1"></canvas>
<script src="cms.js"></script>
</body>
</html>
Oleksandr Karpovich [JB]
07/12/2023, 8:22 AMkotlin.js.ir.output.granularity=whole-program
in gradle.properties?Daniele B
07/12/2023, 8:26 AMUncaught Error: Error loading module 'cms'. Its dependency '@js-joda/core' was not found. Please, check whether '@js-joda/core' is loaded prior to 'cms'.
at cms.js:99:13
at cms.js:103:2
Oleksandr Karpovich [JB]
07/12/2023, 8:43 AMmoduleName = "cms"
in build.gradle.kts, I received a similar error.
I keep looking into why it's happening.
In the meantime you can test if removing "moduleName=..." helps.
The default script name can be found in /.../build/compileSync/js/main/developmentExecutable/kotlin
after running jsBrowserRun
So index.html would need to be updated too
The default name should be the same as the gardle module name iircOleksandr Karpovich [JB]
07/12/2023, 8:56 AMjs(IR) {
moduleName = "cms"
browser {
commonWebpackConfig {
outputFileName = "cms.js"
}
}
binaries.executable()
}
also kotlin.js.ir.output.granularity=whole-program
shouldn't be necessary nowDaniele B
07/12/2023, 9:25 AMkotlin.js.ir.output.granularity=whole-program
.
Without specifying the moduleName and linking the "CMS-jsApp.js" file, I still get:
CMS-jsApp.js:8 Uncaught Error: Error loading module 'cms'. Its dependency 'androidx-runtime' was not found. Please, check whether 'androidx-runtime' is loaded prior to 'cms'.
at CMS-jsApp.js:8:13
at CMS-jsApp.js:21:2
but it works correctly if I link "cms.js" and I specify:
moduleName = "cms"
browser {
commonWebpackConfig {
outputFileName = "cms.js"
}
}
binaries.executable()
Oleksandr Karpovich [JB]
07/12/2023, 9:28 AMCMS-jsApp.js:8 Uncaught Error: Error loading module 'cms'
It's weird that no module name specified but it still mentiones module 'cms'. Maybe something was cached.
Anyway, good to hear the last configuration worked for youDaniele B
07/12/2023, 9:30 AMrootProject.name = "CMS"
Daniele B
07/12/2023, 9:31 AMCMS-jsApp.js:8 Uncaught Error: Error loading module 'CMS-jsApp'. Its dependency 'androidx-runtime' was not found. Please, check whether 'androidx-runtime' is loaded prior to 'CMS-jsApp'.
at CMS-jsApp.js:8:13
at CMS-jsApp.js:21:2
Oleksandr Karpovich [JB]
07/12/2023, 9:33 AMactually I cleaned the project and tried again, and the error isWas it without this config?
moduleName = "cms"
browser {
commonWebpackConfig {
outputFileName = "cms.js"
}
}
Daniele B
07/12/2023, 9:44 AMjs(IR) {
browser()
binaries.executable()
}
Daniele B
07/12/2023, 9:48 AMDaniele B
07/12/2023, 9:48 AMOleksandr Karpovich [JB]
07/12/2023, 9:55 AMZac Sweers
01/05/2024, 5:32 AM