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

Multimodule project js can't resolve files, images, localizations

Open nevrozza opened this issue 2 years ago • 7 comments

Module not found: Error: Can't resolve 'images/layer.png' in 'C:\Files\Code\Melody\build\js\packages\Melody-jsApp\kotlin' Did you mean './images/layer.png'?

Work good on jvm and android, but on JS i have this problem.

Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules). If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

This error appears when i add these file to generated path.

utils build.gradle.kts `plugins { id("browser-setup") id("android-setup") id("multiplatform-setup") id("dev.icerock.mobile.multiplatform-resources") }

kotlin {

sourceSets {
    val commonMain by getting {
        dependencies {
            api(Deps.Moko.Resources.res)
        }

    }
    val androidMain by getting {
        dependsOn(commonMain)
    }
    val desktopMain by getting {
        dependsOn(commonMain)
    }
    val jsMain by getting {
        dependsOn(commonMain)
    }
    val iosMain by getting {
        dependsOn(commonMain)
    }

}

}

multiplatformResources { multiplatformResourcesPackage = "com.melody.melody" }`

nevrozza avatar Nov 27 '23 14:11 nevrozza

hi! did you add id("dev.icerock.mobile.multiplatform-resources") plugin in your web app build.gradle ?

Alex009 avatar Nov 28 '23 12:11 Alex009

Hello! It works now (почти). For two days I thought that I had it as web app's plugin... Now I added it in web app build.gradle and changed utils build.gradle (multiplatformResourcesPackage -> "com.melody.melody.common.utils").

But now I have a different problem: ERROR in ./kotlin/Melody-common-utils.js 84:16-43 Module not found: Error: Can't resolve 'images/layer.png' in 'C:\Files\Code\Melody\build\js\packages\Melody-jsApp\kotlin' Did you mean './images/layer.png'? Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules). If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too. I think problem in this: ` public actual object images : ResourceContainer<ImageResource> { public actual val layer: ImageResource = ImageResource(fileUrl = js("require("images/layer.png")") as String, fileName = "layer.png")

public override fun values(): List<ImageResource> = listOf(layer)

} `

nevrozza avatar Nov 28 '23 19:11 nevrozza

Hey,

Did you resolve your issue @nevrozza ? I encounter the exact same problem on my multi modules project.

feozdax avatar Dec 18 '23 14:12 feozdax

@feozdax Did you encounter this problem in the first stage or in the second?

nevrozza avatar Dec 19 '23 13:12 nevrozza

I am stuck at this part Module not found: Error: Can't resolve 'images/ic_works_medium.svg' in '/Users/Documents/workspace/Synthese/build/js/packages/web/kotlin'.

I already added id("dev.icerock.mobile.multiplatform-resources") plugin to my web app build.gradle.kts. But still same issue

feozdax avatar Dec 21 '23 16:12 feozdax

do you have a discord? I can drop you peaces of my project

nevrozza avatar Dec 22 '23 19:12 nevrozza

Sorry for the delay. I finally understood what was wrong.

What is really important, is to apply plugin dev.icerock.mobile.multiplatform-resources to every module involved into resources management. And second point, you need to expose your dependencies via api and not implementation. Otherwise, resources will not be available for final module (web app for instance). This is why I had this issue "Module not found: Error: Can't resolve 'images/ic_works_medium.svg' "

Now everything is fine. Thank for the help @nevrozza

feozdax avatar Jan 09 '24 11:01 feozdax