kotlin-hands-on / web-app-react-kotlin-js-gradle

https://play.kotlinlang.org/hands-on/Building%20Web%20Applications%20with%20React%20and%20Kotlin%20JS/
136 stars 115 forks source link

Execution failed for task ':browserDevelopmentRun' #15

Closed hillold closed 3 years ago

hillold commented 3 years ago

I get this error when I run the project

Execution failed for task ':browserDevelopmentRun'.
> [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
      at WebpackCLI.makeCommand (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\webpack-cli\lib\webpack-cli.js:108:21)
      at ServeCommand.apply (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\@webpack-cli\serve\lib\index.js:41:19)
      at loadCommandByName (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\webpack-cli\lib\webpack-cli.js:626:35)
      at Command.<anonymous> (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\webpack-cli\lib\webpack-cli.js:1091:23)
      at Command.listener [as _actionHandler] (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\commander\index.js:922:31)
      at Command._parseCommand (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\commander\index.js:1503:14)
      at Command.parse (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\commander\index.js:1292:10)
      at Command.parseAsync (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\commander\index.js:1318:10)
      at WebpackCLI.run (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\webpack-cli\lib\webpack-cli.js:1123:28)
      at runCLI (workspace\web-app-react-kotlin-js-gradle\build\js\node_modules\webpack-cli\lib\bootstrap.js:11:19)
hillold commented 3 years ago

Following the solution here, I added this to gradle.properties:

kotlin.js.webpack.major.version=4

It fixed the reported error, but I was getting this error:

Error: Cannot find module 'webpack-cli/bin/config-yargs'

To fix this, I had to downgrade webpack CLI version:

rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin> {
    rootProject.the<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension>().versions.webpackCli.version = "3.3.12"
}
PavleMomirovic commented 3 years ago

@hillold I have the same problem, and have gotten to the part where I should downgrade webpack CLI. Where should I copy the code snippet that you showed above? I am sorry, I am new at React projects and never have worked with so many dependencies.

pontakornth commented 3 years ago

@hillold Where the downgrade webpack CLI is put?