https://kotlinlang.org logo
#javascript
Title
# javascript
j

Jilles van Gurp

03/28/2023, 3:06 AM
Related to the error I posted earlier, I've been digging around and narrowed down the problem a bit. It appears webpack is failing on the js code generated by the kotlin compiler with a bit misleading error. It actually displays the bit of code it crashes on. I traced that back to one of my own libraries. I fixed the bit of code and then I got a similar error back that I traced back to a bit of code from the koin library that does some things with nano timestamps that involve dividing by some large double number. ``````
Here's the stack trace:
Copy code
2023-03-28T05:01:39.247+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See <https://webpack.js.org/concepts#loaders>
2023-03-28T05:01:39.247+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   |       Companion_getInstance_3();
2023-03-28T05:01:39.247+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   |       var tmp1_div = 1000000.0;
2023-03-28T05:01:39.247+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   >       tmp$ret$0 = tmp0_div.if() / tmp1_div;
2023-03-28T05:01:39.247+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   |       tmp$ret$1 = new Pair(Unit_getInstance(), tmp$ret$0);
2023-03-28T05:01:39.247+0200 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   |       tmp$ret$2 = tmp$ret$1.m4_1;
this is the crucial bit of code. With ripgrep I tracked it down to this bit of innocent looking koin code
whatever is happening is seems to involve a bit of math that ends up dividing by 1000000.0 which is something it had in common with my own library that I removed. This compiles fine. It's just when webpack tries to minify this that the thing blows up.
I assume this may have something to do with javascript not having 64 bit doubles?
this worked fine until kotlin 1.7.22. All version of kotlin 1.8 that I've tried fail on this.
I would appreciate some ways to work around this. I'm not an expert on webpack but I assume the terser plugin or whatever is being used has some weird and wonderful new bugs in its latest incarnation. How does one disable that or replace it with something less flaky (and preferably faster)?
Alternatively this could be a compiler change in 1.8 that is triggering this somehow.
e

ephemient

03/28/2023, 3:24 AM
the
.if () /
looks highly suspicious - may be parsed as
Copy code
if ()   // empty condition
    /   // start of regex
👍 1
j

Jilles van Gurp

03/28/2023, 3:26 AM
right that would explain the misleading reference to webpack loaders
Here's the compiled js code for this:
Copy code
129   │   protoOf(KoinApplication).n79 = function (modules) {
 130   │     if (this.j79_1.y78_1.s79(Level_INFO_getInstance())) {
 131   │       var tmp$ret$2;
 132   │       // Inline function 'org.koin.core.time.measureDuration' call
 133   │       var tmp$ret$1;
 134   │       // Inline function 'org.koin.core.time.measureTimedValue' call
 135   │       var start = KoinPlatformTimeTools_getInstance().o79();
 136   │       loadModules(this, modules);
 137   │       var value = Unit_getInstance();
 138   │       var stop = KoinPlatformTimeTools_getInstance().o79();
 139   │       var tmp$ret$0;
 140   │       // Inline function 'kotlin.Long.div' call
 141   │       var tmp0_div = stop.t8(start);
 142   │       Companion_getInstance_3();
 143   │       var tmp1_div = 1000000.0;
 144   │       tmp$ret$0 = tmp0_div.if() / tmp1_div;
 145   │       tmp$ret$1 = new Pair(Unit_getInstance(), tmp$ret$0);
 146   │       tmp$ret$2 = tmp$ret$1.m4_1;
 147   │       var duration = tmp$ret$2;
 148   │       var count = this.j79_1.v78_1.p79();
 149   │       this.j79_1.y78_1.r79(Level_INFO_getInstance(), 'loaded ' + count + ' definitions in ' + duration + ' ms');
 150   │     } else {
 151   │       loadModules(this, modules);
from
compileSync/js/main/productionExecutable/kotlin/core-koin-core-js-ir.js
10 Views