moko-resources
moko-resources copied to clipboard
Multimodule project js can't resolve files, images, localizations
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" }`
hi!
did you add id("dev.icerock.mobile.multiplatform-resources") plugin in your web app build.gradle ?
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)
} `
Hey,
Did you resolve your issue @nevrozza ? I encounter the exact same problem on my multi modules project.
@feozdax Did you encounter this problem in the first stage or in the second?
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
do you have a discord? I can drop you peaces of my project
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