Hi!
I’m building a project using kotlin/JS (org.jetbrains.kotlin.js) and React and while I can get it to work, most of the time I get errors that disappear when I simply run it again. These errors include:
<PATH TO PROJECT>/build/js/packages/<PROJECT NAME>/package.json (No such file or directory)
Cannot find node module "webpack-dev-server/bin/webpack-dev-server.js" in "<PATH TO PROJECT>/build/js/packages/<PROJECT NAME>"
Cannot find node module "webpack/bin/webpack.js" in "<PATH TO PROJECT>/build/js/packages/<PROJECT NAME>"
and sometimes others (cannot follow symlink or something), although these two are the most common.
The most annoying part is that these errors also break the hot-reload of browserRun or browserRun --continuous, having me to restart the run.
My current build.gradle.kts:
import org.gradle.kotlin.dsl.*
plugins {
kotlin("js") version "1.3.61"
kotlin("kapt") version "1.3.61"
id("com.diffplug.gradle.spotless") version "3.26.1"
}
apply {
// plugin("kotlin-dce-js")
}
group = "org.example"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
jcenter()
maven(url = "https://dl.bintray.com/kotlin/kotlinx")
maven(url = "https://dl.bintray.com/kotlin/kotlin-eap")
maven(url = "https://kotlin.bintray.com/js-externals")
maven(url = "https://kotlin.bintray.com/kotlin-js-wrappers")
}
// attempt at linter
spotless {
kotlin {
ktlint()
}
kotlinGradle {
// same as kotlin, but for .gradle.kts files (defaults to '*.gradle.kts')
target("*.gradle.kts", "additionalScripts/*.gradle.kts")
ktlint()
}
}
kotlin {
target {
useCommonJs()
nodejs()
browser {
compilations.all {
kotlinOptions {
metaInfo = true
outputFile = "${project.buildDir.path}/js/${project.name}.js"
sourceMap = true
sourceMapEmbedSources = "always"
moduleKind = "commonjs"
main = "call"
}
}
}
}
sourceSets {
main {
dependencies {
implementation("org.jetbrains:annotations:16.0.2")
implementation(kotlin("stdlib-js"))
implementation("org.jetbrains.kotlinx:kotlinx-html-js:0.6.12")
implementation("org.jetbrains:kotlin-react:16.9.0-pre.89-kotlin-1.3.60")
implementation("org.jetbrains:kotlin-react-dom:16.9.0-pre.89-kotlin-1.3.60")
implementation("io.data2viz:d2v-data2viz-js:0.8.0-RC1")
implementation("org.jetbrains:kotlin-extensions:1.0.1-pre.89-kotlin-1.3.60")
implementation("org.jetbrains:kotlin-css:1.0.0-pre.89-kotlin-1.3.60")
implementation("org.jetbrains:kotlin-css-js:1.0.0-pre.89-kotlin-1.3.60")
implementation("org.jetbrains:kotlin-styled:1.0.0-pre.89-kotlin-1.3.60")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.11.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.1")
implementation(npm("react", "16.12.0"))
implementation(npm("react-dom", "16.12.0"))
implementation(npm("react-draggable"))
implementation(npm("react-list"))
implementation(npm("react-window"))
implementation(npm("inline-style-prefixer"))
implementation(npm("core-js"))
implementation(npm("@material-ui/core"))
implementation(npm("@material-ui/icons"))
implementation(npm("styled-components"))
implementation(npm("jquery"))
}
}
}
}