Reputation: 4036
Build fails with error messages:
ERROR in ./output.js Module not found: Error: Can't resolve 'common' in 'C:\Users\User\Documents\MultiPlatformTodo\web\web' @ ./output.js 340:91-108
ERROR in ./output.js Module not found: Error: Can't resolve 'kotlin' in 'C:\Users\User\Documents\MultiPlatformTodo\web\web' @ ./output.js 340:18-35
ERROR in ./output.js Module not found: Error: Can't resolve 'kotlin-react' in 'C:\Users\User\Documents\MultiPlatformTodo\web\web' @ ./output.js 340:37-60
ERROR in ./output.js Module not found: Error: Can't resolve 'kotlin-react-dom' in 'C:\Users\User\Documents\MultiPlatformTodo\web\web' @ ./output.js 340:62-89
ERROR in ./output.js Module not found: Error: Can't resolve 'kotlinx-coroutines-core' in 'C:\Users\User\Documents\MultiPlatformTodo\web\web' @ ./output.js 340:110-144
ERROR in ./output.js Module not found: Error: Can't resolve 'kotlinx-html-js' in 'C:\Users\User\Documents\MultiPlatformTodo\web\web' @ ./output.js 340:146-172
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':web:webpack-bundle'. node webpack.js failed (exit code = 2)
Js module build.gradle
is defined as follows:
apply plugin: 'org.jetbrains.kotlin.frontend'
apply plugin: 'kotlin2js'
kotlinFrontend {
npm {
dependency("react", "16.6.0")
dependency("react-dom", "16.6.0")
dependency("@material-ui/core", "1.4.3")
}
sourceMaps = true
webpackBundle {
bundleName = "mpnotes"
contentPath = file('src/main/web')
}
}
dependencies {
implementation project(':common')
implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-html-js:0.6.11"
implementation "org.jetbrains:kotlin-react:16.6.0-pre.61-kotlin-1.3.0"
implementation "org.jetbrains:kotlin-react-dom:16.6.0-pre.61-kotlin-1.3.0"
}
compileKotlin2Js {
kotlinOptions {
outputFile = "${projectDir}/web/output.js"
metaInfo = true
moduleKind = "commonjs"
sourceMap = true
}
}
and settings.gradle
:
enableFeaturePreview('GRADLE_METADATA')
rootProject.name = 'MultiPlatformTodo'
include 'android'
include 'web'
include 'common'
Here's the content of the common
module:
apply plugin: 'kotlin-multiplatform'
kotlin {
targets {
fromPreset(presets.jvm, 'jvm')
fromPreset(presets.js, 'js')
}
sourceSets {
commonMain {
dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version"
}
}
commonTest {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-test-common"
implementation "org.jetbrains.kotlin:kotlin-test-annotations-common"
}
}
jvmMain {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
}
}
jsMain {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$coroutines_version"
}
}
}
}
kotlin {
experimental {
coroutines "enable"
}
}
Upvotes: 2
Views: 1585
Reputation: 2073
I know its a bit late, but if you add apply plugin: 'kotlin-dce-js'
in build.gradle
you are good to go
Upvotes: 1
Reputation: 3654
I see two likely issues.
The first is that instead of kotlin2js
you should use multiplatform gradle plugins, ie kotlin-multiplatform
, which is newer and will have more long-term support, or kotlin-platform-js
, which is probably an easier drop-in replacement for your current setup.
The other problem is the line implementation project(':common')
. This tells gradle you're consuming the common module as a js dependency, since this is a js project. For kotlin-platform-js
you should instead use expectedBy project(':common')
to link it as a common dependency. For kotlin-multiplatform
there are a bunch more changes you need to your dependency configuration. You can see some details here
Upvotes: 1