I’m trying the functionality to use NPM instead of...
# eap
c
I’m trying the functionality to use NPM instead of yarn for Kotlin/JS, and I might have found a bug as my app builds but my JS tests fail to run. Is there something else that needs to be configured besides the property
kotlin.js.yarn=false
?
Copy code
> Task :browser-route-lib:jsBrowserTest
Error during loading "kotlin-test-js-runner/karma-kotlin-reporter.js" plugin:
  Cannot find module 'karma/lib/utils/path-utils'
Require stack:
- ~/kmp-sigma/build/js/packages_imported/kotlin-test-js-runner/0.0.1/karma-kotlin-reporter.js
- ~/kmp-sigma/build/js/packages/Sigma-browser-route-lib-test/node_modules/karma/lib/plugin.js
- ~/kmp-sigma/build/js/packages/Sigma-browser-route-lib-test/node_modules/karma/lib/server.js
- ~/kmp-sigma/build/js/packages/Sigma-browser-route-lib-test/node_modules/karma/lib/cli.js
- ~/kmp-sigma/build/js/packages/Sigma-browser-route-lib-test/node_modules/karma/bin/karma
Cannot load "sourcemap", it is not registered!
  Perhaps you are missing some plugin?
Server start failed on port 9876: Error: No provider for "framework:mocha"! (Resolving: framework:mocha)
Can not load reporter "karma-kotlin-reporter", it is not registered!
  Perhaps you are missing some plugin?
java.lang.IllegalStateException: command '~/.gradle/nodejs/node-v20.12.1-darwin-arm64/bin/node' exited with errors (exit code: 1)
youtrack 1
t
@Ilya Goncharov [JB] maybe you could help here? 🤔
i
Do you have a reproducer project?
c
No, not yet; I just discovered this a few minutes ago in a large project and distilling it down may take some time.
a
@Carter, feel free to create a ticket via YouTrack regarding the issue, if you have a reproducer project. Thank you!
i
For history, NPM is not very good in incremental installs. In such cases it is better to remove
package-lock.json
at all (both in
kotlin-js-store
and in
build/js
)
c
Ilya and I discussed this in more depth privately and got most of the way there by deleting the build directory and the lockfile and regenerating it. It doesn’t re-generate incrementally. There is still a challenge with resolving the package lock up front, and I have a corner case that I’ll describe here: 1. I delete the lock file and the build directory 2. I run
./gradlew resolveAll kotlinStorePackageLock
(resolveAll described below) 3. I commit the lockfile 4. I run
./gradlew check
or
./gradlew assemble
and it succeeds 5. I run
./gradlew :server-app:prepareDockerDeployment
and it fails (this task just takes the server-app JAR file, plus a Dockerfile, and puts them in a separate directory) 6. I delete the lock file and the build directory 7. I run
./gradlew :server-app:prepareDockerDeployment kotlinStorePackageLock
but Git shows no differences between the re-generated lock file and the one committed in step 1 The
resolveAll
task is present in all modules via a convention plugin, and it does the following
Copy code
tasks {
    // invoke with `./gradlew resolveAll --write-locks` when updating dependencies
    register("resolveAll", ResolveAllDependencies::class)
}

@CacheableTask
abstract class ResolveAllDependencies : DefaultTask() {
    @get:Input
    abstract val dependencies: SetProperty<ResolvedComponentResult>

    init {
        @Suppress("LeakingThis")
        with(dependencies) {
            finalizeValueOnRead()
            project.configurations.all {
                if (isCanBeResolved) {
                    add(incoming.resolutionResult.rootComponent)
                }
            }
        }
    }

    @TaskAction
    fun resolve() { /* no-op */
    }
}
:server-app
is a JVM application. The one tricky thing it does is copy the output of
:browser-app
which is a Compose for Web app into its JAR file. It does that by the following browser-app/build.gradle.kts
Copy code
configurations.register("browserAppProduction") {
    isCanBeConsumed = true
    isCanBeResolved = true
}.also { configuration ->
    artifacts {
        val resourcesTask = tasks.getByName("jsBrowserDistribution")
        resourcesTask.outputs.files.forEach { file ->
            add(configuration.name, file) {
                builtBy(resourcesTask)
            }
        }

        val webpackTask = tasks.getByName("jsBrowserProductionWebpack")
        webpackTask.outputs.files.forEach { file ->
            add(configuration.name, file) {
                builtBy(webpackTask)
            }
        }
    }
}
server-app/build.gradle.kts
Copy code
kotlin {
    sourceSets {
        getByName("jvmMain") {
            dependencies {
                implementation(
                    project(
                        mapOf(
                            "path" to ":browser-app",
                            "configuration" to "browserAppProduction"
                        )
                    )
                )
            }
        }
    }
}
a
I have created a ticket KT-69684