icerockdev / moko-resources

Resources access for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
1.08k stars 121 forks source link

Expected object 'SharedRes' has no actual declaration in module <package_name:site> for JS #576

Closed EchoEllet closed 5 months ago

EchoEllet commented 1 year ago

I have created kobweb project which is a framework built on top of compose web

I add moko-resouces as plugin, library and define the versions in libs.versions.toml

[versions] jetbrains-compose = "1.5.1" kobweb = "0.14.0" kotlin = "1.9.10" multiplatform-resources = "0.23.0"

[libraries]
kobweb-api = { module = "com.varabyte.kobweb:kobweb-api", version.ref = "kobweb" }
kobweb-core = { module = "com.varabyte.kobweb:kobweb-core ", version.ref = "kobweb" }
kobweb-silk-core = { module = "com.varabyte.kobweb:kobweb-silk", version.ref = "kobweb" }
kobweb-silk-icons-fa = { module = "com.varabyte.kobweb:kobweb-silk-icons-fa", version.ref = "kobweb" }
kobweb-silk-icons-mdi = { module = "com.varabyte.kobweb:kobweb-silk-icons-mdi", version.ref = "kobweb" }
#kobwebx-markdown = { module = "com.varabyte.kobwebx:kobwebx-markdown", version.ref = "kobweb" }
multiplatform-resources = { module = "dev.icerock.moko:resources", version.ref = "multiplatform-resources" }

[plugins]
jetbrains-compose = { id = "org.jetbrains.compose", version.ref = "jetbrains-compose" }
kobweb-application = { id = "com.varabyte.kobweb.application", version.ref = "kobweb" }
kobweb-library = { id = "com.varabyte.kobweb.library", version.ref = "kobweb" }
#kobwebx-markdown = { id = "com.varabyte.kobwebx.markdown", version.ref = "kobweb" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
multiplatform-resources = { id = "dev.icerock.mobile.multiplatform-resources", version.ref = "multiplatform-resources" }

build.gradle.kts:

import com.varabyte.kobweb.gradle.application.util.configAsKobwebApplication

plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.jetbrains.compose)
    alias(libs.plugins.kobweb.application)
    alias(libs.plugins.multiplatform.resources)
//    id("dev.icerock.mobile.multiplatform-resources")
//    alias(libs.plugins.kobwebx.markdown)
}

group = "com.ahmedhnewa.landing_page"
version = "1.0-SNAPSHOT"

kobweb {
    app {
        index {
            description.set("Powered by Kobweb")
        }
    }
}

kotlin {
    configAsKobwebApplication("landing_page", includeServer = false)

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(compose.runtime)
//                api("dev.icerock.moko:resources:0.23.0")
                api(libs.multiplatform.resources)
//                api("dev.icerock.moko:resources-compose:0.23.0") // for compose multiplatform

            }
        }

        val jsMain by getting {
            dependencies {
                implementation(compose.html.core)
                implementation(libs.kobweb.core)
                implementation(libs.kobweb.silk.core)
                implementation(libs.kobweb.silk.icons.fa)
//                implementation(libs.kobwebx.markdown)
            }
        }

//        val jvmMain by getting {
//            dependencies {
//                implementation(libs.kobweb.api)
//            }
//        }
    }
}

multiplatformResources {
    multiplatformResourcesPackage = "com.ahmedhnewa.landing_page"
    multiplatformResourcesClassName = "SharedRes" // optional, default MR
}

I want to use it only for js browser but I get this error

Execution failed for task ':site:compileKotlinJs'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

The generated SharedRes: Expected object 'SharedRes' has no actual declaration in module for JS

code:

package com.ahmedhnewa.alrayada_landing_page

import dev.icerock.moko.resources.AssetResource
import dev.icerock.moko.resources.ColorResource
import dev.icerock.moko.resources.FileResource
import dev.icerock.moko.resources.FontResource
import dev.icerock.moko.resources.ImageResource
import dev.icerock.moko.resources.PluralsResource
import dev.icerock.moko.resources.ResourceContainer
import dev.icerock.moko.resources.StringResource

public expect object SharedRes {
  public object strings : ResourceContainer<StringResource> {
    public val hello_world: StringResource
  }

  public object plurals : ResourceContainer<PluralsResource>

  public object images : ResourceContainer<ImageResource>

  public object fonts : ResourceContainer<FontResource>

  public object files : ResourceContainer<FileResource>

  public object colors : ResourceContainer<ColorResource>

  public object assets : ResourceContainer<AssetResource>
}
luangs7 commented 1 year ago

same here downgrade Kotlin to 1.8.20 and Compose to 1.5.0 works here unfortunately, it affects another lib

EchoEllet commented 1 year ago

same here downgrade Kotlin to 1.8.20 and Compose to 1.5.0 works here unfortunately, it affects another lib

I just created my own solution to localization. It's much better for kotlin and kmp with only the web, in my opinion, at least for strings

luangs7 commented 1 year ago

expect 1.9.0 support?

CaelumF commented 1 year ago

FYI as a workaround you can ensure that the sourcesets have dependsOn(commonMain) and kotlin.srcDir("build/generated/moko/desktopMain/src") where desktopMain is replaced with the appropriate directory to match the source set

Alex009 commented 8 months ago

fix in #575

ExNDY commented 5 months ago

will be fixed in 0.24.0, please check in 0.24.0-alpha-6

Alex009 commented 5 months ago

should be fixed in 0.24.0-beta-1