I'm trying to compile a kotlin file test.kt
using kotlinc-js
:
fun main() {
println("Hello world!")
val a = add(7, 22)
println("Added to get $a")
}
fun add(x: Int, y: Int): Int {
val z = x + y
println(z)
println("Hello $y")
return z
}
I downloaded the kotlinc zip file from github, worked through some errors, and eventually arrived here:
kotlinc/bin/kotlinc-js -Xir-produce-js -libraries ".\kotlinc\lib\kotlin-stdlib-js.jar" -ir-output-dir build -ir-output-name test.js test.kt
This seems to be successful with this output:
info: produce executable: build
info: cache directory: null
info: executable production duration: 3740ms
It creates the build directory, but there are no files within it. I can't figure out what to do from here.
I've tried adding more libraries like so:
kotlinc/bin/kotlinc-js -Xir-produce-js -libraries ".\kotlinc\lib\kotlin-stdlib-js.jar;.\kotlinc\lib\kotlin-stdlib.jar" -ir-output-dir build -ir-output-name test.js test.kt
But any library after the first one gives the following error:
error: source entry is not a Kotlin file
I found a YouTrack issue which detailed similar problems to those I was having initially (which is how I came up with the command I am using right now), but I don't know how to continue from here.
I am using Kotlin 1.8.22 in PowerShell 7.3.4 on Windows 11
I ran into the same problem and tested many flags combinations until I discovered that it works with absolute path for -ir-output-dir
flag. I wonder where the output go when this path is relative.