Hey!  I'm trying to add <https://github.com/Kotlin...
# kotlinx-datetime
j
Hey!  I'm trying to add https://github.com/Kotlin/kotlinx-datetime to my kotlinjs project, but I'm getting errors related to joda-timezone.  I've added 
implementation(npm("@js-joda/timezone", "2.3.0"))
 to my 
jsMain
 dependencies, and also added a block to the beginning of my 
Main.kt
 file:
Copy code
@JsModule("@js-joda/timezone")
@JsNonModule
external object JsJodaTimeZoneModule

private val jsJodaTz = JsJodaTimeZoneModule
I build with 
jsBrowserDistribution
but if I look at the build output javascript file, the very first few lines are:
Copy code
(function (root, factory) {
  if (typeof define === 'function' && define.amd)
    define(['exports', '@js-joda/timezone', '@js-joda/core'], factory);
  else if (typeof exports === 'object')
    factory(module.exports, require('@js-joda/timezone'), require('@js-joda/core'));
  else {
    if (typeof JsJodaTimeZoneModule === 'undefined') {
      throw new Error("Error loading module 'turntaker-js'. Its dependency '@js-joda/timezone' was not found. Please, check whether '@js-joda/timezone' is loaded prior to 'turntaker-js'.");
    }if (typeof this['@js-joda/core'] === 'undefined') {
      throw new Error("Error loading module 'turntaker-js'. Its dependency '@js-joda/core' was not found. Please, check whether '@js-joda/core' is loaded prior to 'turntaker-js'.");
    }root['turntaker-js'] = factory(typeof this['turntaker-js'] === 'undefined' ? {} : this['turntaker-js'], JsJodaTimeZoneModule, this['@js-joda/core']);
  }
}(this, function (_, JsJodaTimeZoneModule, $module$_js_joda_core) {
which would seem to imply that the JsJodaTimeZoneModule is not being included, or certainly not being included prior to the check running
d
What kind of errors are you getting? What you're describing is what we also do in our project and it does work for us. Also the output javascript file looks pretty normal to me, at least it looks similar to our output.
The only difference I see is that we use
^2.5.0
for the version, instead of
2.3.0
, but I can't image that would change much.
j
The error is
Its dependency '@js-joda/timezone' was not found. Please, check whether '@js-joda/timezone' is loaded prior to 'turntaker-js'
. Given that these are the first few lines of javascript that are run, it is clear by inspection that js-joda is not being initialized prior to the dependency check. The dependency check is the first thing that happens in the module, and the
jsJodaTz =
line happens deep within the function scope, after the dependency check.
d
Does it only happen when building for distribution? I.e. does it work when running it using
./gradlew run
? For distribution we use the
assemble
task, not
jsBrowserDistribtution
, perhaps that's the difference?
j
It is a compose multiplatform project and 
gradlew run
 will launch the JVM variant.  I assume the equivalent you're suggesting would be 
jsBrowserRun
 which seems to build successfully and launches a localhost:8081 but returns a 404 ("Cannot GET /turntaker-js.js") for my main javascript output file.
d
I tried to reproduce it, but in the end, didn't manage to. Simple projects with the same configuration as yours work just fine, and the time zones are available from the browser.
If you share a (preferably small) publically available project where this happens, it will be easier to diagnose this.
z
@Dmitry Khalanskiy [JB] @Vsevolod Tolstopyatov [JB] if you still want a repro for this, I filed one here https://github.com/Kotlin/kotlinx-datetime/issues/334
111 Views