moko-resources icon indicating copy to clipboard operation
moko-resources copied to clipboard

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

Open EchoEllet opened this issue 1 year ago • 5 comments

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 <com.ahmedhnewa.landing_page:site> 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>
}

EchoEllet avatar Sep 11 '23 16:09 EchoEllet

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

luangs7 avatar Sep 13 '23 02:09 luangs7

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

EchoEllet avatar Sep 13 '23 02:09 EchoEllet

expect 1.9.0 support?

luangs7 avatar Sep 25 '23 17:09 luangs7

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

CaelumF avatar Oct 05 '23 08:10 CaelumF

fix in #575

Alex009 avatar Jan 14 '24 14:01 Alex009

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

ExNDY avatar Apr 17 '24 05:04 ExNDY

should be fixed in 0.24.0-beta-1

Alex009 avatar Apr 19 '24 15:04 Alex009