Hello, In my multi-modules multiplatform library, ...
# javascript
l
Hello, In my multi-modules multiplatform library, I see a lot of occurences of the following in the Gradle logs:
Copy code
Please choose a JavaScript environment to build distributions and run tests.
Not choosing any of them will be an error in the future releases.
kotlin {
    js {
        // To build distributions for and run tests on browser or Node.js use one or both of:
        browser()
        nodejs()
    }
}
The problem is that whenever I try to replace
js()
or
js { useCommonJs() }
with
js(BOTH) { nodejs(); browser() }
, I get that error on build:
Copy code
Could not create an instance of type org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinNodeJs.
> Failed to apply plugin [class 'org.gradle.language.base.plugins.LifecycleBasePlugin']
   > Cannot add task 'clean' as a task with that name already exists.
I'm a little surprised the recommendation doesn't work… what could be wrong here, and is there workarounds?
d
@louiscad Did you add
binaries.executable()
to your JS section when enabling the IR compiler? This is exactly what caught me out in the post above ☝️ as kindly advised by @Robert Jaros. For whatever reason, this is now explicitly required for the IR compiler to output executable JS. See Choosing Execution Environment from https://kotlinlang.org/docs/reference/js-project-setup.html#choosing-execution-environment I know the error message you provided seems unrelated, but I got similarly misleading errors when omitting
binaries.executable()
.
l
@darkmoon_uk I just tried with
binaries.executable()
, but I get the exact same error. BTW, I'd rather not use it since I'm only targetting Kotlin/JS users for all my JS compatible modules for now, and enable it on a per-module basis if it makes sense to use in a Typescript/Javascript project.
i
Usually it can be related with creating of your own
clean
task, do you have it? Do you have
clean
task on your root project for example?
l
Yes, many Android projects have this:
Copy code
task<Delete>("clean") {
    delete(rootProject.buildDir)
}
or the groovy DSL equivalent created by Android Studio templates (maybe not in recent versions, but the fact is that other projects will have it)
So, the Kotlin multiplatform should reuse any existing
clean
task if it exists instead of forcing creation I guess… should I open an issue on youtrack @Ilya Goncharov [JB]?
i
Unfortunately it is default behavioir if standard
LifecycleBasePlugin
, we just apply it You can create issue of course, but as I understand we have such one
Maybe it will be real cool to create such question on StackOverflow and answer on it, because of its good indexable of search engines for future folks
👍 2
l
Great idea, I'll do this. You want to answer or should I do both Q&A?
i
Feel free to do both, if you want, I can share my answer only tomorrow 🙂
l
I found another question with the same issue and an answer… I need to search again on Google… I've been too much used to be among the firsts to encounter issues when it comes to Kotlin MPP… https://stackoverflow.com/questions/55118903/error-cannot-add-task-clean-as-a-task-with-that-name-already-exists