Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@js-joda/core could not be found - jsMain logging in KMM project #7

Open
daniel-toth-leeder opened this issue Nov 14, 2022 · 2 comments

Comments

@daniel-toth-leeder
Copy link

I'm facing an issue when tried to do any logging in JS in a KMM project.
I'm using the latest 0.16 version of canard, see excerpt from the build.gradle.kts

val commonMain by getting {
            dependencies {
                ...
                implementation("org.kodein.log:canard:0.16.0")
                implementation("org.kodein.di:kodein-di:7.14.0")
                implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
                ...
            }
        }

See stack trace:

Unable to resolve module @js-joda/core from <project_src>/node_modules/<js_lib_folder_name>/Kotlin-DateTime-library-kotlinx-datetime-js-ir.js: @js-joda/core could not be found within the project or in these directories:
  ../node_modules
  1716 |   //endregion
  1717 |   return _;
> 1718 | }(module.exports, require('@js-joda/core'), require('./kotlin-kotlin-stdlib-js-ir.js'), require('./kotlinx-serialization-kotlinx-serialization-core-js-ir.js')));
       |                            ^
  1719 |
  1720 | //# sourceMappingURL=Kotlin-DateTime-library-kotlinx-datetime-js-ir.js.map
  1721 |

A possible workaround I found for the issue is to add the @js-joda/core as an npm dependency to the jsMain sourceSet definition.

val jsMain by getting {
            dependsOn(commonMain)
            dependencies {
                implementation(npm("@js-joda/core", "5.4.2"))
            }
        }

Having this in the sourceSet closure, I am able to use canard in JS and I can see the logs with the default LoggingFactory in the console.

@romainbsl
Copy link
Member

Do you have a reproducer?

I have no issue with the following configuration (KMP full stack project JVM + JS)

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        withJava()
        testRuns["test"].executionTask.configure {
            useJUnitPlatform()
        }
    }
    js(IR) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }
        }
    }
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("org.kodein.log:canard:0.16.0")
            }
        }
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jvmMain by getting {
            dependencies {
                implementation("io.ktor:ktor-server-netty:2.0.2")
                implementation("io.ktor:ktor-server-html-builder-jvm:2.0.2")
                implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2")
            }
        }
        val jvmTest by getting
        val jsMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlin-wrappers:kotlin-react:18.2.0-pre.346")
                implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:18.2.0-pre.346")
                implementation("org.jetbrains.kotlin-wrappers:kotlin-emotion:11.9.3-pre.346")
            }
        }
        val jsTest by getting
    }
}

In commonMain I have:

val commonLogger = LoggerFactory.default.newLogger(Logger.Tag("Canard", "Common"))

in jsMain I have:

val jsLogger = LoggerFactory.default.newLogger(Logger.Tag("Canard", "JS"))

fun main() {
    commonLogger.info { "Common Logger says hello in JS!" }
    jsLogger.info { "KJS Logger says hello!" }


    val container = document.createElement("div")
    document.body!!.appendChild(container)

    val welcome = Welcome.create {
        name = "Kotlin/JS"
    }
    createRoot(container).render(welcome)
}

image

@daniel-toth-leeder
Copy link
Author

Would it be possible to leave this issue open for now?
I'll try to come back you with a sample project.
I gave it another look and realised, that the issue I have might be related to the fact that the result of the KMM project ( the js library) is used inside a react native application.
We were not able to reproduce the issue running the js library on node.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants