Does Kotlin `1.8` no longer generate `.d.ts` files...
# javascript
s
Does Kotlin
1.8
no longer generate
.d.ts
files or is there a configuration I’m missing? When on Kotlin
1.7.21
they generate in
build/developmentLibrary/
but with
1.8
they are no longer there.
b
It should. Are you using BOTH compiler mode by any chance? I think that dropped a support for dts
s
I’m using
IR
. I’ll try setting up a new project to be sure it’s not something unique in our project.
Yep even with the Full-Stack Web Application wizard, Kotlin
1.7.21
generates a
.d.ts
and updating to
1.8
it no longer does.
b
Maybe there's a new flag now that you need to flip explicitly? I assume you already use binaries.library()
s
Yeah checking through the changelog now. I tried with both
binaries.library()
and
binaries.executable()
too
b
Are you running some specific task to get that or just a catch-all "build" task?
s
/gradlew jsBrowserDevelopmentLibraryDistribution
b
Could be a case of task responsibilities changing maybe? Can you try "gradlew clean build"?
s
I’ve done a clean between each attempt to be sure. It doesn’t generate a
.d.ts
file in the
js/packages/<Project>/kotlin/
anymore either.
b
I'm also always using useCommonJs() Might be worth seeing if that changes anything if you don't use it yet
s
Hmm nope doesn’t work with
useCommonJs()
either on my end. I appreciate the help btw!
Just for the repro, I used the Full-Stack Web Application wizard in Intellij then changed
binaries.executable()
to
binaries.library()
. Running
jsBrowserDevelopmentLibraryDistribution
with
1.7.21
creates
.d.ts
files. Changing it to
kotlin("multiplatform") version "1.8.0"
and commenting out the deprecated
cssSupport.enabled = true
option, it no longer generates
.d.ts
files.
b
Booting up my pc to try it out
🙏 1
Aha! Looks like dts are now only generated for productionLibraries (so my initial suggestion to run
./gradlew clean build
would've worked for you.
Also be sure to have at least one @JsExport in your code.
image.png
s
Ah ha, you are amazing! Thank you for figuring that out. I see the
.d.ts
files now using productionLibraries.
🎉 1
b
Pro tip, when stuff is suddently missing always run the most expensive/generic task you can think of to check if it was really missing or just moved someplace else
In this case that was
build
or
assemble
s
I appreciate the tip! I’ll keep that in mind next time something goes wrong.
c
@Big Chungus while you're sharing pro tips, do you know of a way to easily find out which task creates a specific file? My current strategy of "look at the tasks that get executed, then execute each of them in order until the file exists" takes ages 😕
b
That would be my first instinct as well. To be more efficient you might check gradle scan - I think it list out task inputs and outputs. Alternatively something like this might work
Copy code
tasks {
  all {
    doFirst {
      println("$(task.name) outputs: $(outputs.files)")
    }
}
c
Oh, I'll try that, thanks
b
Let us know if any of the options worked
w
I don’t know if I can necropost this, but I have the same problem with kotlin 1.8.20 and I can’t find any d.ts file, not with binaries.executable() and jsBrowserProductionWebpack and neither with binaries.library() and jsBrowserProductionLibraryDistribution
b
Dts files are only generated for binaries.library()
Also they are skipped if your code has no @JsExport members
Here's your checklist for dts gen: 1. Use IR backend 2. Use binaries.library() 3. Have at least one entity in your code annotated with @JsExport
w
thanks! I think they changed the rules again.. It works with kotlin 1.8.0 but not with 1.8.20.. I’m trying with 1.8.10 now
my results: kotlin 1.8.0 -> d.ts are generated kotlin 1.8.10 -> doesn’t build: error An unexpected error occurred: “https://registry.yarnpkg.com/acorn-import-assertions/-/acorn-import-assertions-1.8.10.tgz: Request failed \“404 Not Found\“”. kotlin 1.8.20 -> it builds but d.ts are not generated
j
@willyrs or anyone, have you figured this out? I’m on kotlin 1.8.20, nothing i’ve done has gotten d.ts files to generate. using:
Copy code
js(IR) {
    nodejs()
    binaries.library()
}
worked fine with any 1.7.x versions we used
a
@jeran add
generateTypeScriptDefinitions()
Copy code
js(IR) {
    generateTypeScriptDefinitions()
    binaries.library()
}
2
j
sadly, i am getting this
a
are you already set kotlin version to 1.8.20? May be you returned it to 1.7.0?
j
i wondering if it might’ve been introduced in 1.8.21
no, it looks like it should be there… gonna keep digging into it
in case anyone comes across this
generateTypeScriptDefinitions()
was definitely the answer to my issue. some local transient build issue was causing gradle not to find it, but it is present in 1.8.20
👍 1
217 Views