JVM modules are fine, but not JS modules
# javascript
s
JVM modules are fine, but not JS modules
n
Are you developing a Kotlin multi-platform project?
Do you use Gradle as a build system?
s
yes and yes
n
This may sound like a silly question, have you applied the Kotlin JS Gradle plugin?
y
I have the same issue
gradle (kotlin-dsl) project,
kotlin2js
plugin applied
n
What version of Gradle and Kotlin is being used?
y
4.10
n
Is the kotlin-platform-js Gradle plugin being applied? That plugin is needed along with the kotlin2js one in order for the Kotlin multi-platform system to work properly.
y
nope
Copy code
import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.60")
    }
}

apply {
    plugin("kotlin2js")
}

dependencies {
    add("compile", "org.jetbrains.kotlin:kotlin-stdlib-js:1.2.60")
    add("compile", "org.jetbrains.kotlinx:kotlinx-html-js:0.6.11")
}

repositories {
    jcenter()
}

tasks.withType(Kotlin2JsCompile::class.java){
    kotlinOptions.sourceMap = true
    kotlinOptions.sourceMapEmbedSources = "always"
//    kotlinOptions.moduleKind = "commonjs"
}
n
It is unusual to use the add function to add a dependency.
y
Ho, what's the correct way ?
n
For compile and test compile dependencies the compile and testCompile functions are used, except in cases like with Kotlin JS where the plugin isn't published properly in which case the "compile" and "testCompile" functions are used instead (yes, the function names are surrounded in double quotes).
y
Ok. It works. I've upgraded to 1.2.61 by the way. But the new->package is still missing and there is a new->directory.
s
Yes, I think I am like Yann. It is seeing that it is a JS module, it compiles correctly (and checks code properly), but something is off because the package/directory thing is wrong and "Move" refactorings don't update the package.
I'll try to create a sample project and create a ticket today.
n
IntelliJ has a bug where it does package refactorings incorrectly (in some situations). In the worst case where IntelliJ doesn't have the option to create a new package a new directory is created, and the kt file is prepended with the package. Packages in Kotlin unlike Java don't have to match to an exact directory. Multiple packages can reside in a single directory, where it doesn't matter which directory a package resides in as long as the Kotlin compiler can find it.
s
Yeah, this isn't the problem. There's clearly a problem where IntelliJ isn't properly recognizing the source directory. This worked fine up until the latest versions of the plugin.