Hi! I am new to kotlin/js, so please excuse if thi...
# javascript
t
Hi! I am new to kotlin/js, so please excuse if this is already answered, but i couldn't find it anywhere. Is there any possiblity to debug kotlin/js in intellij? IJ automatically generates a node js run configuration for you, but i could not find any way to make it use the kotlin.js file also. The official documentation(https://www.jetbrains.com/help/idea/run-debug-configuration-kotlin-javascript.html) states that there is a Kotlin-JavaScript Run Configuration, but i could find it neither in 2018.1 nor in 2018.2 EAP.
e
i have do it with nodejs run configuration (don’t know does idea preinstalled plugin nodejs or not, so if you don’t have it please install) with it in main method appears greed arrow there you could start debug
t
yes that happens for me too, but instead of running normally i get:
Copy code
throw new Error("Error loading module 'link-lookup-multi-js'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'link-lookup-multi-js'.");

Error: Error loading module 'link-lookup-multi-js'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'link-lookup-multi-js'.
it can't load the kotlin.js file
e
this error can be solved by running task in gradle (which will copy all js files to .node_modules folder):
Copy code
plugins {
    id "com.moowork.node" version "1.2.0"
}

def nodeModules = project.getProjectDir().getPath() + "/node_modules/"

node {
    nodeModulesDir = file(nodeModules)
}

task populateNodeModules(type: Copy, dependsOn: [compileKotlin2Js, npmInstall]) {
    from compileKotlin2Js.destinationDir
    into nodeModules

    afterEvaluate {
        configurations.testCompile.each {
            if (it.absolutePath.endsWith(".jar")) {
                from zipTree(it.absolutePath).matching {
                    include '*.js'
                    include '*.js.map'
                }
            }
        }
    }
}
t
ah ok i am currently not using node explicitly. I just created a multiplatform kotlin project. Is it possible without all the node configuration?
e
I think yes, just remove all npm tasks from
populateNodeModules
task and set correctly
into
folder
v
I can get IJ to debug kotlinjs transparently. This is what my gradle build file looks like:
Copy code
buildscript {
    ext.kotlin_version = '1.2.41'
    ext.serialization_version = '0.5.0'
    repositories {
        jcenter()
        maven { url "<https://kotlin.bintray.com/kotlinx>" }
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:$serialization_version"
    }
}
apply plugin: 'kotlin2js'
apply plugin: 'kotlinx-serialization'

repositories {
    jcenter()
    maven { url "<https://kotlin.bintray.com/kotlinx>" }
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
    compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$serialization_version"
}

compileKotlin2Js.kotlinOptions {
    outputFile = "${projectDir}/node/index.js"
    moduleKind = "commonjs"
    sourceMap = true
}
Notice the
sourceMap = true
at the bottom, that was essential for the debugger to work transparently. I also have
Delegate IDE build/run actions to gradle
enabled. You can find that option in
Build, Execution, Deployment > Build tools > Gradle > Runner
Gradle creates a single JS file that is eventually run. Location of that file is defined in
compileKotlin2Js.kotlinOption.outputFile
e
with this configuration I have same problems, kotlin.js not found. Could you look with that configuration idea loading debug? With my case idea creates same nodejs config and run with it