Kotlin/JS, Gradle Plugin : Unable to load '@webpack-cli/serve' command
Asked Answered
Q

3

15

I was doing the tutorial for React Kotlin and couldnt even finish the setup step because the server does not start.

The code is unchanged : https://github.com/kotlin-hands-on/web-app-react-kotlin-js-gradle

Stacktrace:

[webpack-cli] Unable to load '@webpack-cli/serve' command
[webpack-cli] TypeError: options.forEach is not a function
[webpack-cli] TypeError: options.forEach is not a function

I saw this issue : https://github.com/webpack/webpack-cli/issues/2990 but I'm unable to implement the fix proposed (change the webpack-cli version and remove the webpack-cli/serve from yarn.lock) because I can't find how to change these on the kotlin js gradle plugin.

Even simple browser application from intelliJ is broken with the same error.

Quinonez answered 12/10, 2021 at 9:8 Comment(1)
Github discussion hereEndophyte
B
11

Try to update webpack-cli:

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java) {  
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().versions.webpackCli.version = "4.9.0"
}
Burlington answered 12/10, 2021 at 10:8 Comment(2)
Where should this line be added?Ow
build.gradle.ktsBurlington
M
21

Had the same issue: adding this option to the project gradle.properties

kotlin.js.webpack.major.version=4

fixed it - reference: https://kotlinlang.org/docs/js-project-setup.html#webpack-version

Metabolize answered 13/10, 2021 at 8:7 Comment(1)
This option set webpack-cli version in 3.3.12. Downdate is a matter of taste.Burlington
B
11

Try to update webpack-cli:

rootProject.plugins.withType(org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin::class.java) {  
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().versions.webpackCli.version = "4.9.0"
}
Burlington answered 12/10, 2021 at 10:8 Comment(2)
Where should this line be added?Ow
build.gradle.ktsBurlington
U
0

Evgeny's answer didn't work here. Now after 2 days of banging head, and reading kotlin plugin source-code, only the following worked here:

// build.gradle.kts file
kotlinYarn {
    resolution("webpack", "5.73.0")
    resolution("webpack-cli", "4.10.0")
}

It will print a warning when running the task kotlinNpmInstall but the app will run.

Urticaria answered 17/6, 2022 at 20:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.