Jordi
Jordi

Reputation: 2537

Kotlin multiplatform gradle task "jsRun" gives error "[webpack-cli] TypeError: cli.isMultipleCompiler is not a function"

I have a Kotlin multiplatform project with JVM and JS. When executing jsRun gradle task to start the webpack server, it fails with the following error:

Waiting for changes to input files of tasks... (ctrl-d then enter to exit)
[webpack-cli] TypeError: cli.isMultipleCompiler is not a function
[webpack-cli] TypeError: cli.isMultipleCompiler is not a function
    at Command.<anonymous> (C:\MyProject\build\js\node_modules\@webpack-cli\serve\lib\index.js:146:35)
    at async Promise.all (index 1)
    at async Command.<anonymous> (C:\MyProject\build\js\node_modules\webpack-cli\lib\webpack-cli.js:1687:7)

Compilation succeeds and I can serve the project via Ktor, the problem seems to be the webpack dev server.

The package.json that kotlin gradle plugin generates seems to use webpack-cli 4.9.0.

{
  "name": "MyProject-client",
  "version": "1.0.0",
  "main": "kotlin/MyProject-client.js",
  "devDependencies": {
    "sass-loader": "13.0.0",
    "sass": "1.53.0",
    "style-loader": "3.3.1",
    "css-loader": "6.7.1",
    "resolve-url-loader": "5.0.0",
    "webpack": "5.57.1",
    "webpack-cli": "4.9.0",
    "format-util": "1.0.5",
    "source-map-loader": "3.0.0",
    "webpack-dev-server": "4.3.1",
    "dukat": "0.5.8-rc.4"
  },
  "dependencies": {},
  "peerDependencies": {},
  "optionalDependencies": {},
  "bundledDependencies": []
}

This says that it's a bug in webpack-cli 4.9.0 and suggests upgrading to 4.10.0. I don't know if/how webpack versions can be changed in Kotlin/JS.

Upvotes: 3

Views: 932

Answers (1)

Jordi
Jordi

Reputation: 2537

This should be added to build.gradle.kts in the affected project to force the webpack-cli version. This is a workaround until the Kotlin team updates the hardcoded version.

// Fixes webpack-cli incompatibility by pinning the newest version.
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
    versions.webpackCli.version = "4.10.0"
}

Upvotes: 6

Related Questions