Skip to content

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

@daniel-toth-leeder

Description

@daniel-toth-leeder

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions