Using a custom Kotlin Javascript Library from a Kotlin Javascript project

I am using Yested (a Kotlin JS library) in a Kotlin JS project. With Kotlin 1.03 it was working, but after I updated to Kotlin 1.0.5, somehow it isn’t working anymore. If I try to go back to Kotlin 1.0.3, my IntelliJ plugin can’t read the files. I’d rather stick with 1.0.5 anyway, but with 1.0.5 I’m getting is this error in the browser JS console:

webclient_main.js:1180 Uncaught TypeError: Cannot read property ‘yested’ of undefined
on this line:
var div = _.net.yested.with_ji1yox$(new _.net.yested.Div(), _.client.main_kand9s$f);

The .js files for both yested and webclient_main seem to define _. Each project’s .js file declares its own _, but I don’t see anything that pulls in yested into webclient. I’m using KotlinJS’s Module kind of “Plain (put to global scope)”.
I tried calling require(“Yested”), but that didn’t compile because it tried to use a require method that takes a boolean, not a string.

Any help would be very appreciated!

I’ve encountered a similar issue. The problem is that somehow the library is not treated as a library. What build system do you use. I’m using gradle. The strange thing is that external libraries (kotlinx.html) did work.

I’m using gradle in the consuming project, but I’m actually building it in IntelliJ with Ctrl+Shift+F9 after importing it from gradle. Yested uses maven.

I don’t see anything that pulls in yested into webclient

What did pull in Yested into web client before you switched to 1.0.5?

Looks like Yested is not actively developed anymore. It’s pom.xml file tells that framework is built for Kotlin 1.0.2, which is pretty old, and I dont know how you could make it work with 1.0.5. 1.0.2 and 1.0.5 are simplly incompatible between each other. Anyway, you provided too few information. What code are you compiling? What is the stack trace? How do you load JS files?

What pulled in yested in 1.0.2 was the gradle dependency along with the reference in the index.html.

Here is a version of yested that uses Kotlin 1.0.5: GitHub - epabst/yested: A Kotlin framework for building web applications in Javascript.
Run “mvn clean install” in yested.
Then build GitHub - epabst/kotlin-showcase: Kotlin example app with webclient, hybrid mobile using Cordova, and backend. following the steps in the README.md for the webclient.

This stack trace is happens in the browser:
Uncaught TypeError: Cannot read property ‘yested’ of undefined
at Object.main_kand9s$ (http://localhost:63342/kotlin-showcase/build/classes/main/webclient_main.js:53:24)
at http://localhost:63342/kotlin-showcase/build/classes/main/webclient_main.js:59:12
at http://localhost:63342/kotlin-showcase/build/classes/main/webclient_main.js:61:2

I load the JS files by referencing them in the index.html. See https://github.com/epabst/kotlin-showcase/blob/master/webclient/src/main/web/index.html.

I’d be happy to adjust this project if you can provide a working example that I can build locally.

I found the reason. You should find the following lines in pom.xml in Yested project:

<manifestEntries>
  <Implementation-Version>${build.number}</Implementation-Version>
  <Specification-Title>Kotlin JavaScript Lib</Specification-Title>
  <Kotlin-JS-Module-Name>${project.artifactId}</Kotlin-JS-Module-Name>
</manifestEntries>

Remove Specification-Title entry and recompile Yested. That’s because presence of Specification-Title and Kotlin-JS-Module-Name indicates that a module is an “Old Kotlin JS module” (modules like these don’t provide serialized metainformation, their declarations are resolved from packed source code). Kotlin 1.0.5 has broken support of “Old Kotlin JS modules”, and we still not sure what to do: either remove them completely or fix them (which is a little compicated).

Also, you can remove kt sources from Yested jar file, i.e. remove following lines from pom.xml:

<copy todir="${project.build.outputDirectory}">
    <fileset dir="${basedir}/src/main/kotlin">
        <include name="**/*.kt"/>
    </fileset>
</copy>

.meta.js file is enough for modern Kotlin.

1 Like

Thank you! That worked great!