Can’t link a JS script generated from a Kotlin/JS project using IntelliJ IDEA

As stated above, the problem is that I can’t link the compiled JS code from a Kotlin project (called twf) to my web-project. No matter what I try, Chrome outputs an error such as twf.stringToExpression is not a function

As far as I’m concerned, the Kotlin code does compile correctly, and the beginning of an output file twf.js looks as follows:

if (typeof kotlin === 'undefined') {
throw new Error("Error loading module 'twf'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'twf'.");
}var twf = function (_, Kotlin) {
'use strict';
var setOf = Kotlin.kotlin.collections.setOf_mh5how$;

Which means that variable twf does exist. Also, in the same file I found this:

function stringToExpression(string, scope, isMathMl, functionConfiguration, compiledConfiguration) {
if (scope === void 0)
if (isMathMl === void 0)
if (functionConfiguration === void 0) {
}if (compiledConfiguration === void 0)

So the function exists and I can call it with only a string as an input, just like I do in the index.html file (I know that having a bare script inside an HTML file is a bad habit, but it is only a prototype):

<script type="text/javascript">
  var testTaskString = "a-b/c";

Nevertheless, I still get the error I mentioned above and I don’t seem to know with to do about it. How do I solve it?

P.S. This is the <head> part of the page (both kotlin.js and twf.js are linked):

<title>PixiJS Test</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/style.css">
<script src="lib/pixi.js"></script>
<script src="lib/kotlin.js"></script>
<script src="lib/twf.js"></script>

P.P.S. I even put @JsName("stringToExpression") before the function in the Kotlin code before compilation, but that didn’t seem to help.


Looks like this question was just an another instance of the “look through the code that you are using more carefully” problem, since the solution was quite trivial. When I used the console.log(twf) command (since I was sure that the twf variable was declared) I get the following output:

> Object
  > api:
    > stringToExpression: ƒ stringToExpression( ... )
  > baseoperations:

Hence, as far as I’m concered and as far as it works, I had to use the following code to refer to the function instead:

var testTaskString = "a-b/c";

Leave a Reply

Your email address will not be published. Required fields are marked *