# JavaScript

**URL:** https://discuss.kotlinlang.org/c/javascript/13.md?page=2

[Latest](https://discuss.kotlinlang.org/latest.md) · [Categories](https://discuss.kotlinlang.org/categories.md)

**Page:** 3

---

## [How to use pure ESM packages in Kotlin/JS?](https://discuss.kotlinlang.org/t/how-to-use-pure-esm-packages-in-kotlin-js/23720)

<div class="topic-metadata">

**Author:** [@acclimate535](https://discuss.kotlinlang.org/u/acclimate535)\
**Replies:** 1\
**Last updated:** [December 23, 2021, 3:36am UTC](https://discuss.kotlinlang.org/t/how-to-use-pure-esm-packages-in-kotlin-js/23720 "2021-12-23T03:36:27Z")

</div>

Some packages are purse ESM and fail when using @JsModule annotation to provide a type wrapper, for example \> Task :nodeDevelopmentRun FAILED Error \[ERR\_REQUIRE\_ESM\]: Must use import to load ES Module: /.../build/js/n…

---

## [IR compiler: can't extend JS classes](https://discuss.kotlinlang.org/t/ir-compiler-cant-extend-js-classes/23740)

<div class="topic-metadata">

**Author:** [@simonjacobs](https://discuss.kotlinlang.org/u/simonjacobs)\
**Replies:** 0\
**Last updated:** [December 21, 2021, 12:13pm UTC](https://discuss.kotlinlang.org/t/ir-compiler-cant-extend-js-classes/23740 "2021-12-21T12:13:16Z")

</div>

I’ve just spent a few days migrating my app to the IR compiler because Kotlin Serialization wasn’t working properly under the legacy compiler. After that, I’ve now realised that my whole React app relies on the legacy f…

---

## [Actual use of default constructor in java](https://discuss.kotlinlang.org/t/actual-use-of-default-constructor-in-java/23635)

<div class="topic-metadata">

**Author:** [@cloudytech147](https://discuss.kotlinlang.org/u/cloudytech147)\
**Replies:** 2\
**Last updated:** [December 11, 2021, 3:18am UTC](https://discuss.kotlinlang.org/t/actual-use-of-default-constructor-in-java/23635 "2021-12-11T03:18:38Z")

</div>

Default constructors are provided by the compiler when the programmer fails to write any constructor to a class. And it is said that these constructors are used to initialize default values to the class attributes.Howeve…

---

## [How to import local JS functions into Kotlin JS?](https://discuss.kotlinlang.org/t/how-to-import-local-js-functions-into-kotlin-js/23602)

<div class="topic-metadata">

**Author:** [@LifeIsStrange](https://discuss.kotlinlang.org/u/LifeIsStrange)\
**Replies:** 0\
**Last updated:** [December 6, 2021, 3:15pm UTC](https://discuss.kotlinlang.org/t/how-to-import-local-js-functions-into-kotlin-js/23602 "2021-12-06T15:15:44Z")

</div>

I am aware of JsModule for npm dependencies, however my use case is to call a JS function from my Vue project, in my KotlinJS project. This very simple use case seems very hard to achieve. Given a js function a(), I de…

---

## [Fetch in service worker](https://discuss.kotlinlang.org/t/fetch-in-service-worker/23485)

<div class="topic-metadata">

**Author:** [@mihbor](https://discuss.kotlinlang.org/u/mihbor)\
**Replies:** 3\
**Last updated:** [November 19, 2021, 2:40pm UTC](https://discuss.kotlinlang.org/t/fetch-in-service-worker/23485 "2021-11-19T14:40:50Z")

</div>

Trying to use window.fetch() from a service worker throws a ReferenceException saying that window is undefined. The fetch() function itself is available within a service worker since it works when declared like so: ext…

---

## [I cannot extend kotlin.Number](https://discuss.kotlinlang.org/t/i-cannot-extend-kotlin-number/23412)

<div class="topic-metadata">

**Author:** [@fs523577192](https://discuss.kotlinlang.org/u/fs523577192)\
**Replies:** 1\
**Last updated:** [November 8, 2021, 10:06am UTC](https://discuss.kotlinlang.org/t/i-cannot-extend-kotlin-number/23412 "2021-11-08T10:06:20Z")

</div>

I want to implement a BigInteger class like class BigInteger internal constructor(val bigInt: dynamic): Number(), Comparable\<BigInteger\> { ...... override fun toInt(): Int { val myBigInt = this.bigI…

---

## [Complex Declarative UIs](https://discuss.kotlinlang.org/t/complex-declarative-uis/23347)

<div class="topic-metadata">

**Author:** [@tothiz](https://discuss.kotlinlang.org/u/tothiz)\
**Replies:** 6\
**Last updated:** [November 2, 2021, 3:50am UTC](https://discuss.kotlinlang.org/t/complex-declarative-uis/23347 "2021-11-02T03:50:41Z")

</div>

Hi! I’m playing with the idea to add a state-based automatic UI rebuild (a.k.a declarative UI) to my framework (https://zakadabar.io), mostly for the JS target. I used React before and also I’ve checked Compose (core a…

---

## [Kotlin/JS, Gradle + Webpack arguments](https://discuss.kotlinlang.org/t/kotlin-js-gradle-webpack-arguments/21376)

<div class="topic-metadata">

**Author:** [@CameronProbert](https://discuss.kotlinlang.org/u/CameronProbert)\
**Replies:** 5\
**Last updated:** [October 21, 2021, 6:48am UTC](https://discuss.kotlinlang.org/t/kotlin-js-gradle-webpack-arguments/21376 "2021-10-21T06:48:23Z")

</div>

I’m trying to use command line arguments with the gradle build task to set some behaviours in the build process. My project is React in Kotlin/JS (Legacy compiler, with some Kotlin multi-platform libraries), using build.…

---

## [How to set the package name of a compiled Js module](https://discuss.kotlinlang.org/t/how-to-set-the-package-name-of-a-compiled-js-module/22125)

<div class="topic-metadata">

**Author:** [@sofzer](https://discuss.kotlinlang.org/u/sofzer)\
**Replies:** 3\
**Last updated:** [October 19, 2021, 7:37am UTC](https://discuss.kotlinlang.org/t/how-to-set-the-package-name-of-a-compiled-js-module/22125 "2021-10-19T07:37:00Z")

</div>

I am compiling some modules from kotlin to javascript but using the in javascript looks a bit ugly since I have to go into the whole scope of the organization domain to get the necessary class Is there any solution plea…

---

## [Issues after compiling (IR compiler)](https://discuss.kotlinlang.org/t/issues-after-compiling-ir-compiler/23037)

<div class="topic-metadata">

**Author:** [@alzomins](https://discuss.kotlinlang.org/u/alzomins)\
**Replies:** 4\
**Last updated:** [October 14, 2021, 6:45am UTC](https://discuss.kotlinlang.org/t/issues-after-compiling-ir-compiler/23037 "2021-10-14T06:45:22Z")

</div>

Hi all, I’m trying to export 3 very simple classes. @JsExport open class MyFirstClass { open fun myFirstClassFunction() { println("################ MyFirstClass") } } @JsExport open class MySecondClass…

---

## [Compose for Web... how is this in alpha?](https://discuss.kotlinlang.org/t/compose-for-web-how-is-this-in-alpha/22963)

<div class="topic-metadata">

**Author:** [@tothiz](https://discuss.kotlinlang.org/u/tothiz)\
**Replies:** 11\
**Last updated:** [October 6, 2021, 9:18am UTC](https://discuss.kotlinlang.org/t/compose-for-web-how-is-this-in-alpha/22963 "2021-10-06T09:18:53Z")

</div>

While I’m glad that Kotlin/JS gets more and more attention, I can’t really wrap my mind around publishing Compose for Web on jetbrains.com as alpha. To be honest, it is a kinda slap in the face after spending about a ye…

---

## [Hybrid frontend project with Kotlin JS and manually written JS](https://discuss.kotlinlang.org/t/hybrid-frontend-project-with-kotlin-js-and-manually-written-js/23010)

<div class="topic-metadata">

**Author:** [@sschuberth](https://discuss.kotlinlang.org/u/sschuberth)\
**Replies:** 5\
**Last updated:** [September 24, 2021, 12:15pm UTC](https://discuss.kotlinlang.org/t/hybrid-frontend-project-with-kotlin-js-and-manually-written-js/23010 "2021-09-24T12:15:48Z")

</div>

We’re planning a new Kotlin backend (server) / frontend (UI) project. The data models in the backend are written in pure Kotlin (as data classes), and we’d like to also use these data classes in the frontent. So to avoid…

---

## [Function reference instead of anonymous lambda not working?](https://discuss.kotlinlang.org/t/function-reference-instead-of-anonymous-lambda-not-working/22990)

<div class="topic-metadata">

**Author:** [@mlesniak](https://discuss.kotlinlang.org/u/mlesniak)\
**Replies:** 1\
**Last updated:** [September 22, 2021, 2:45am UTC](https://discuss.kotlinlang.org/t/function-reference-instead-of-anonymous-lambda-not-working/22990 "2021-09-22T02:45:52Z")

</div>

Hi, I have a strange problem which I try to understand. I’ve defined private val canvas: HTMLCanvasElement ... fun register(handler: (Event) -\> Unit) { canvas.addEventListener("keydown", handler) …

---

## [Kotlin/JS 1.4, how to output a NPM package?](https://discuss.kotlinlang.org/t/kotlin-js-1-4-how-to-output-a-npm-package/19128)

<div class="topic-metadata">

**Author:** [@lamba92](https://discuss.kotlinlang.org/u/lamba92)\
**Replies:** 4\
**Last updated:** [September 16, 2021, 2:37pm UTC](https://discuss.kotlinlang.org/t/kotlin-js-1-4-how-to-output-a-npm-package/19128 "2021-09-16T14:37:50Z")

</div>

Say you have a simple project with just the Kotlin standard library and one dependency from NPM. What would be a good pattern to output an NPM package? Also which tasks of the Kotlin/JS plugin (or Kotlin/MPP with js()) a…

---

## [Doodle - A pure Kotlin, UI framework for the Web](https://discuss.kotlinlang.org/t/doodle-a-pure-kotlin-ui-framework-for-the-web/18099)

<div class="topic-metadata">

**Author:** [@joe\_bloggs](https://discuss.kotlinlang.org/u/joe_bloggs)\
**Replies:** 9\
**Last updated:** [September 10, 2021, 3:51pm UTC](https://discuss.kotlinlang.org/t/doodle-a-pure-kotlin-ui-framework-for-the-web/18099 "2021-09-10T15:51:18Z")

</div>

I just released Doodle . A pure Kotlin UI framework for the Web. The difference compared to other frameworks is that it is not a nicer way to write HTML/CSS. Doodle apps actually don’t use browser concepts at all. Sing…

---

## [How do I call coroutines from JavaScript?](https://discuss.kotlinlang.org/t/how-do-i-call-coroutines-from-javascript/12098)

<div class="topic-metadata">

**Author:** [@sokatov](https://discuss.kotlinlang.org/u/sokatov)\
**Replies:** 7\
**Last updated:** [August 23, 2021, 6:23pm UTC](https://discuss.kotlinlang.org/t/how-do-i-call-coroutines-from-javascript/12098 "2021-08-23T18:23:09Z")

</div>

The subj. class MyClass() { suspend myFunc() {} } In JS const obj = new MyClass() // obj.myFunc Now how should I gracefully call obj.myFunc?

---

## [\[webpack-cli\] Invalid configuration object](https://discuss.kotlinlang.org/t/webpack-cli-invalid-configuration-object/22711)

<div class="topic-metadata">

**Author:** [@H2k](https://discuss.kotlinlang.org/u/H2k)\
**Replies:** 3\
**Last updated:** [August 17, 2021, 9:01am UTC](https://discuss.kotlinlang.org/t/webpack-cli-invalid-configuration-object/22711 "2021-08-17T09:01:41Z")

</div>

Hi. I am having problems to run a completely new Kotlin/JS-React project created with IntelliJ. Despite the successfull build, I am getting a webpack-cli error complaining about invalid configuration. 07:47:35: Executi…

---

## [Getting coroutine name for logging in Kotlin JS](https://discuss.kotlinlang.org/t/getting-coroutine-name-for-logging-in-kotlin-js/22220)

<div class="topic-metadata">

**Author:** [@MarkusKramer](https://discuss.kotlinlang.org/u/MarkusKramer)\
**Replies:** 11\
**Last updated:** [July 21, 2021, 8:32am UTC](https://discuss.kotlinlang.org/t/getting-coroutine-name-for-logging-in-kotlin-js/22220 "2021-07-21T08:32:42Z")

</div>

Hi. For logging I would like to get the current thread & coroutine id from within a non-suspending function (logging library). In the JVM world logging libraries can get the current thread and coroutine id with Thread.…

---

## [I dont think i am using coroutines correctly here](https://discuss.kotlinlang.org/t/i-dont-think-i-am-using-coroutines-correctly-here/22494)

<div class="topic-metadata">

**Author:** [@huggy](https://discuss.kotlinlang.org/u/huggy)\
**Replies:** 2\
**Last updated:** [July 23, 2021, 11:45pm UTC](https://discuss.kotlinlang.org/t/i-dont-think-i-am-using-coroutines-correctly-here/22494 "2021-07-23T23:45:04Z")

</div>

i want to be able to reuse this call to my server from a JS backend: suspend fun customerSummaryTwo(req: GenericIntEQ) : Deferred\<CustomerPDSummaryDTO\> { val deffered: Deferred\<CustomerPDSummaryDTO\> = Glob…

---

## [When switching to Kotlin \>=1.5.20 then failure 'e.project.sync.GradleSyncState - Unable to load class 'org.antlr.v4.runtime.Lexer occurs'](https://discuss.kotlinlang.org/t/when-switching-to-kotlin-1-5-20-then-failure-e-project-sync-gradlesyncstate-unable-to-load-class-org-antlr-v4-runtime-lexer-occurs/22458)

<div class="topic-metadata">

**Author:** [@SamD](https://discuss.kotlinlang.org/u/SamD)\
**Replies:** 6\
**Last updated:** [July 21, 2021, 4:35pm UTC](https://discuss.kotlinlang.org/t/when-switching-to-kotlin-1-5-20-then-failure-e-project-sync-gradlesyncstate-unable-to-load-class-org-antlr-v4-runtime-lexer-occurs/22458 "2021-07-21T16:35:24Z")

</div>

When using Kotlin \<=15.10 everything works as expected. Then I switch to Kotlin 1.5.20. During reloading of gradle project following error occurs in the event log: This is an unexpected error. Please file a bug containi…

---

## [Problem with generated d.ts. file](https://discuss.kotlinlang.org/t/problem-with-generated-d-ts-file/22337)

<div class="topic-metadata">

**Author:** [@alzomins](https://discuss.kotlinlang.org/u/alzomins)\
**Replies:** 3\
**Last updated:** [July 7, 2021, 12:04pm UTC](https://discuss.kotlinlang.org/t/problem-with-generated-d-ts-file/22337 "2021-07-07T12:04:37Z")

</div>

Dear all, I am trying to export kotlin files to using it as ts. However, after build and generate all files (package.json, d.ts and js), error occurred when I try to use d.ts file Example interface is: @JsExport inte…

---

## [PWA: Serviceworker unable to cache main .js script using Gradle's browserDevelopmentRun](https://discuss.kotlinlang.org/t/pwa-serviceworker-unable-to-cache-main-js-script-using-gradles-browserdevelopmentrun/22191)

<div class="topic-metadata">

**Author:** [@MSauer89](https://discuss.kotlinlang.org/u/MSauer89)\
**Replies:** 0\
**Last updated:** [June 23, 2021, 11:15am UTC](https://discuss.kotlinlang.org/t/pwa-serviceworker-unable-to-cache-main-js-script-using-gradles-browserdevelopmentrun/22191 "2021-06-23T11:15:25Z")

</div>

Dear reader, I have recently been tinkering with a simple PWA and wanted to try out using a ServiceWorker in order for it to run offline. First, I created a main project and a seperate ServiceWorker project. Both comp…

---

## [@JsName("Name") does not export function anymore Kotlin 1.5](https://discuss.kotlinlang.org/t/jsname-name-does-not-export-function-anymore-kotlin-1-5/21857)

<div class="topic-metadata">

**Author:** [@Harald.Luebeck](https://discuss.kotlinlang.org/u/Harald.Luebeck)\
**Replies:** 2\
**Last updated:** [June 22, 2021, 2:36pm UTC](https://discuss.kotlinlang.org/t/jsname-name-does-not-export-function-anymore-kotlin-1-5/21857 "2021-06-22T14:36:06Z")

</div>

@JsName(“initRuntime”) fun initRuntime() { Runtime() } Function initRuntime is not exported in Module. Build with gradle 7.0.2

---

## [Other File for Gradle index.html](https://discuss.kotlinlang.org/t/other-file-for-gradle-index-html/22183)

<div class="topic-metadata">

**Author:** [@Harald.Luebeck](https://discuss.kotlinlang.org/u/Harald.Luebeck)\
**Replies:** 0\
**Last updated:** [June 22, 2021, 2:23pm UTC](https://discuss.kotlinlang.org/t/other-file-for-gradle-index-html/22183 "2021-06-22T14:23:17Z")

</div>

Hello, is it possible to use an other File as index.html ? How can i specify that gradle should use for example myIndex.html ?

---

## [Compile a JS library with types defined in NPM dependency](https://discuss.kotlinlang.org/t/compile-a-js-library-with-types-defined-in-npm-dependency/22053)

<div class="topic-metadata">

**Author:** [@jsfr](https://discuss.kotlinlang.org/u/jsfr)\
**Replies:** 5\
**Last updated:** [June 10, 2021, 1:53pm UTC](https://discuss.kotlinlang.org/t/compile-a-js-library-with-types-defined-in-npm-dependency/22053 "2021-06-10T13:53:46Z")

</div>

I’m trying to write a library using the new Kotlin/JS IR compiler. Specifically, I want to write the library using Kotlin, but to publish it as a NPM package to be used in a Typescript/Node project. I have a NPM depende…

---

## [Zakadabar: an MPP library for full-stack development](https://discuss.kotlinlang.org/t/zakadabar-an-mpp-library-for-full-stack-development/22025)

<div class="topic-metadata">

**Author:** [@tothiz](https://discuss.kotlinlang.org/u/tothiz)\
**Replies:** 0\
**Last updated:** [June 4, 2021, 4:45pm UTC](https://discuss.kotlinlang.org/t/zakadabar-an-mpp-library-for-full-stack-development/22025 "2021-06-04T16:45:05Z")

</div>

Hello! I’m happy to share our project with the Kotlin community. It is an open source software library for full-stack application development. We wanted to have a solid platform to build our applications on, with the …

---

## [@JsExport issues on abstract function](https://discuss.kotlinlang.org/t/jsexport-issues-on-abstract-function/21900)

<div class="topic-metadata">

**Author:** [@alzomins](https://discuss.kotlinlang.org/u/alzomins)\
**Replies:** 0\
**Last updated:** [May 21, 2021, 6:14am UTC](https://discuss.kotlinlang.org/t/jsexport-issues-on-abstract-function/21900 "2021-05-21T06:14:28Z")

</div>

Is there allowed to annotate @JsExport on abstract classes ? @JsExport abstract class SampleClass(id: Int, name: String) { var id: Int? = id var name: String? = name @JsExport abstract fun description(t…

---

## [Dynamic data change in js() in .kt](https://discuss.kotlinlang.org/t/dynamic-data-change-in-js-in-kt/21802)

<div class="topic-metadata">

**Author:** [@alzomins](https://discuss.kotlinlang.org/u/alzomins)\
**Replies:** 4\
**Last updated:** [May 18, 2021, 2:47pm UTC](https://discuss.kotlinlang.org/t/dynamic-data-change-in-js-in-kt/21802 "2021-05-18T14:47:02Z")

</div>

Hello, I am completely new to JS and Kotlin/JS, so be kind :slight\_smile: So, I have a custom JS file and function like this: function playUrl(url) { var options = {}; var player = videojs(‘my-video\_html5\_api’, opti…

---

## [Generating Typescript with the multiplatform plugin](https://discuss.kotlinlang.org/t/generating-typescript-with-the-multiplatform-plugin/18032)

<div class="topic-metadata">

**Author:** [@camlane](https://discuss.kotlinlang.org/u/camlane)\
**Replies:** 2\
**Last updated:** [May 6, 2021, 4:21pm UTC](https://discuss.kotlinlang.org/t/generating-typescript-with-the-multiplatform-plugin/18032 "2021-05-06T16:21:02Z")

</div>

I am using the kotlin multiplatform plugin 1.4 M2 and cant seem to work out how to generate typescript files (.d.ts) instead of js A snippet of my build is below kotlin { sourceSets { commonMain { } } js(IR) { us…

---

## [Linking JS stdlib to generated kdoc](https://discuss.kotlinlang.org/t/linking-js-stdlib-to-generated-kdoc/21712)

<div class="topic-metadata">

**Author:** [@marcel.svitalsky.gmail.com](https://discuss.kotlinlang.org/u/marcel.svitalsky.gmail.com)\
**Replies:** 0\
**Last updated:** [May 5, 2021, 12:07pm UTC](https://discuss.kotlinlang.org/t/linking-js-stdlib-to-generated-kdoc/21712 "2021-05-05T12:07:59Z")

</div>

Developing a Kotlin/JS project, we are generating KDoc using Dokka Maven plugin. However standard JS library classes are presented as ERROR CLASS in the generated doc. Example: having function like this: fun HTMLElemen…

[Previous page](https://discuss.kotlinlang.org/c/javascript/13.md?page=1)

[Next page](https://discuss.kotlinlang.org/c/javascript/13.md?page=3)
