我在 kotlin 前端 Gradle 插件上启动了 Kotlin/JS 反应库。我有以下错误:
> Task :web:webpack-bundle FAILED
js/kotlinx-html-js.js
Module not found: Error: Can't resolve 'kotlin' in '/home/marcin/Projects/EduKotlinAcademy/web/build/node_modules_imported/kotlinx-html-js'
@ ../node_modules_imported/kotlinx-html-js/kotlinx-html-js.js 3:4-42
@ ../node_modules_imported/kotlin-react-dom/kotlin-react-dom.js
@ ./web.js
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':web:webpack-bundle'.
> node webpack.js failed (exit code = 2)
看起来在 kotlinx-html-js 上找不到对 Kotlin 的依赖。虽然我定义了 Kotlin,但它应该可以很好地生成。
对于此配置:
group "org.kotlinacademy" version "1.0-SNAPSHOT"
apply plugin: 'kotlin2js'
apply plugin: 'org.jetbrains.kotlin.frontend'
repositories {
jcenter()
}
kotlinFrontend {
npm {
dependency("webpack-cli", "v2.0.12")
dependency("react", "15.6.1")
dependency("react-dom", "15.6.1")
dependency("react-router-dom", "4.2.2")
dependency("jquery")
dependency("react-markdown")
}
sourceMaps = true
webpackBundle {
bundleName = "main"
contentPath = file('src/main/web')
proxyUrl = "http://localhost:8090"
}
}
dependencies {
compile project(':common-js')
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:0.22.5"
compile("org.jetbrains.kotlinx:kotlinx-html-js:0.6.10") { force = true }
compile 'org.jetbrains:kotlin-react:16.3.1-pre.27-kotlin-1.2.30'
compile "org.jetbrains:kotlin-react-dom:16.3.1-pre.27-kotlin-1.2.30"
}
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.outputFile = "$project.buildDir.path/js/${project.name}.js"
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
kotlinOptions.main = "call" }