2

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"
    }
}
3
  • Please also post the content of the common project build script. Commented Dec 2, 2018 at 17:36
  • @Ilya just updated the question with the common project Commented Dec 2, 2018 at 22:37
  • @EdsonMenegatti Any chance you could resolve it. Commented Sep 26, 2019 at 14:12

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

The js module I mentioned here is not a js library, but rather a regular js module that uses the common library. The kotlin2js plugin is required to convert the kotlin code in it into js so it can be refenced in the html file.
1

I know its a bit late, but if you add apply plugin: 'kotlin-dce-js' in build.gradle you are good to go

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.