# JavaScript

**URL:** https://discuss.kotlinlang.org/c/javascript/13.md

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

---

## [About the JavaScript category](https://discuss.kotlinlang.org/t/about-the-javascript-category/1340)

<div class="topic-metadata">

**Author:** [@Roman\_Belov](https://discuss.kotlinlang.org/u/Roman_Belov)\
**Replies:** 0\
**Last updated:** [December 4, 2015, 7:59am UTC](https://discuss.kotlinlang.org/t/about-the-javascript-category/1340 "2015-12-04T07:59:26Z")

</div>

Development with Kotlin/JS. See also a related #javascript channel in Kotlin Slack (you can sign up here).

---

## [Value classes in Kotlin JS](https://discuss.kotlinlang.org/t/value-classes-in-kotlin-js/26167)

<div class="topic-metadata">

**Author:** [@swi](https://discuss.kotlinlang.org/u/swi)\
**Replies:** 2\
**Last updated:** [December 24, 2025, 10:25am UTC](https://discuss.kotlinlang.org/t/value-classes-in-kotlin-js/26167 "2025-12-24T10:25:31Z")

</div>

Hello, Can someone tell me why we can’t export value classes to js? I can’t find any documentation on this. I’m using kotlin multiplatform in my project with kotlin 1.8 and the new IR compiler. If I annotate a value c…

---

## [Compile one Kotlin file to one JS file with kotlinc-js without Gradle](https://discuss.kotlinlang.org/t/compile-one-kotlin-file-to-one-js-file-with-kotlinc-js-without-gradle/30895)

<div class="topic-metadata">

**Author:** [@fish](https://discuss.kotlinlang.org/u/fish)\
**Replies:** 2\
**Last updated:** [December 19, 2025, 8:13am UTC](https://discuss.kotlinlang.org/t/compile-one-kotlin-file-to-one-js-file-with-kotlinc-js-without-gradle/30895 "2025-12-19T08:13:23Z")

</div>

I eschew Gradle and would like something simpler just for testing simple stuff, I have tried so hard to get this to work but I can’t seem to figure out how to compile ONE Kotlin file to ONE JavaScript file. All the infor…

---

## [Null safety in javascript](https://discuss.kotlinlang.org/t/null-safety-in-javascript/6160)

<div class="topic-metadata">

**Author:** [@mattmook](https://discuss.kotlinlang.org/u/mattmook)\
**Replies:** 10\
**Last updated:** [November 10, 2025, 3:19pm UTC](https://discuss.kotlinlang.org/t/null-safety-in-javascript/6160 "2025-11-10T15:19:15Z")

</div>

I’ve started writing multi-platform modules and pretty quickly have started noticing some inconsistencies between JVM and JS and as such wanted to get a better understanding of what I should be doing. For example, given…

---

## [How can set the scope for the output npm package (i.e. set the package name)?](https://discuss.kotlinlang.org/t/how-can-set-the-scope-for-the-output-npm-package-i-e-set-the-package-name/16335)

<div class="topic-metadata">

**Author:** [@Bradleycorn](https://discuss.kotlinlang.org/u/Bradleycorn)\
**Replies:** 3\
**Last updated:** [August 5, 2025, 10:47pm UTC](https://discuss.kotlinlang.org/t/how-can-set-the-scope-for-the-output-npm-package-i-e-set-the-package-name/16335 "2025-08-05T22:47:53Z")

</div>

I have a fairly standard Kotlin Multiplatform library project that produces library targets for android, jvm, and JavaScript. My project includes a single module, let’s call it ‘my-module’. When I assemble the project, I…

---

## [Specify nodejs executable for Kotlin Gradle plugin instead of downloading it](https://discuss.kotlinlang.org/t/specify-nodejs-executable-for-kotlin-gradle-plugin-instead-of-downloading-it/18889)

<div class="topic-metadata">

**Author:** [@Ballmerpeaking](https://discuss.kotlinlang.org/u/Ballmerpeaking)\
**Replies:** 4\
**Last updated:** [May 17, 2025, 6:48pm UTC](https://discuss.kotlinlang.org/t/specify-nodejs-executable-for-kotlin-gradle-plugin-instead-of-downloading-it/18889 "2025-05-17T18:48:10Z")

</div>

Is there a way to specify a nodejs executable (i.e. use $PATH to resolve it) in the Kotlin Gradle plugin instead of the downloaded one? The problem is the following: I use NixOS which doesn’t have a traditional filesyst…

---

## [Importation of JS functions in Kotlin](https://discuss.kotlinlang.org/t/importation-of-js-functions-in-kotlin/21789)

<div class="topic-metadata">

**Author:** [@alzomins](https://discuss.kotlinlang.org/u/alzomins)\
**Replies:** 11\
**Last updated:** [March 14, 2025, 4:11pm UTC](https://discuss.kotlinlang.org/t/importation-of-js-functions-in-kotlin/21789 "2025-03-14T16:11:47Z")

</div>

Dear all, Is there any possibility to import some JS file (example.js) with function e.g: function myFunction(p1, p2) { return p1 \* p2; } into Kotlin main function and using it like fun main() { myFunction(5,5) } …

---

## [JSModule external class constructor](https://discuss.kotlinlang.org/t/jsmodule-external-class-constructor/29712)

<div class="topic-metadata">

**Author:** [@meo209](https://discuss.kotlinlang.org/u/meo209)\
**Replies:** 0\
**Last updated:** [January 7, 2025, 9:58am UTC](https://discuss.kotlinlang.org/t/jsmodule-external-class-constructor/29712 "2025-01-07T09:58:37Z")

</div>

The .d.ts file for the Conn class looks like this: export declare class Conn { constructor(botOptions: BotOptions, options?: Partial\<ConnOptions\>); } This is my MCProxy.kt: @JsModule("@icetank/mcproxy") @JsNonModu…

---

## [Kotlin JS - ktor websocket client loses connection, and doesn't seem to ping](https://discuss.kotlinlang.org/t/kotlin-js-ktor-websocket-client-loses-connection-and-doesnt-seem-to-ping/29418)

<div class="topic-metadata">

**Author:** [@ibsh](https://discuss.kotlinlang.org/u/ibsh)\
**Replies:** 1\
**Last updated:** [October 21, 2024, 8:18pm UTC](https://discuss.kotlinlang.org/t/kotlin-js-ktor-websocket-client-loses-connection-and-doesnt-seem-to-ping/29418 "2024-10-21T20:18:48Z")

</div>

Hi all, I’m writing a client web app with Kotlin JS and have used various web examples to cobble together a websocket connection with the ktor client. fun start() { val client = HttpClient(Js) { install(Web…

---

## [How do you give focus to a div in kotlin react](https://discuss.kotlinlang.org/t/how-do-you-give-focus-to-a-div-in-kotlin-react/11672)

<div class="topic-metadata">

**Author:** [@huggy](https://discuss.kotlinlang.org/u/huggy)\
**Replies:** 2\
**Last updated:** [September 4, 2024, 12:39pm UTC](https://discuss.kotlinlang.org/t/how-do-you-give-focus-to-a-div-in-kotlin-react/11672 "2024-09-04T12:39:00Z")

</div>

Having problems giving focus in a kotlin react project, has anyone done this?

---

## [React in Kotlin/JS, What I learned (long but useful read)](https://discuss.kotlinlang.org/t/react-in-kotlin-js-what-i-learned-long-but-useful-read/16168)

<div class="topic-metadata">

**Author:** [@Jolanrensen](https://discuss.kotlinlang.org/u/Jolanrensen)\
**Replies:** 19\
**Last updated:** [August 13, 2024, 3:04pm UTC](https://discuss.kotlinlang.org/t/react-in-kotlin-js-what-i-learned-long-but-useful-read/16168 "2024-08-13T15:04:47Z")

</div>

Hi everyone! Note: Hopefully I can post my entire project later, but as it’s a university project it would be considered fraud to publish it :confused:. Why React? Recently for University, we had to make a visualizati…

---

## [Clipboard copy with formatting in Kotlin/JS](https://discuss.kotlinlang.org/t/clipboard-copy-with-formatting-in-kotlin-js/26889)

<div class="topic-metadata">

**Author:** [@vhd.afr](https://discuss.kotlinlang.org/u/vhd.afr)\
**Replies:** 2\
**Last updated:** [July 20, 2024, 3:55am UTC](https://discuss.kotlinlang.org/t/clipboard-copy-with-formatting-in-kotlin-js/26889 "2024-07-20T03:55:11Z")

</div>

I am working on a Kotlin multiplatform project. I want to support copy action with formatting. There are a plenty of page in the web implementing it in javascript. All of them are almost same and do it like this: cons…

---

## [Usage of "globalThis" in the TouchEvent class from web.uievents namespace](https://discuss.kotlinlang.org/t/usage-of-globalthis-in-the-touchevent-class-from-web-uievents-namespace/28414)

<div class="topic-metadata">

**Author:** [@Boubalou](https://discuss.kotlinlang.org/u/Boubalou)\
**Replies:** 0\
**Last updated:** [April 5, 2024, 1:05pm UTC](https://discuss.kotlinlang.org/t/usage-of-globalthis-in-the-touchevent-class-from-web-uievents-namespace/28414 "2024-04-05T13:05:55Z")

</div>

Hey all! We had to support older TV devices such as Samsung TV on Chrome 63 and stumbled on an error while using Kotlin JS and the TouchEvent class from the web.uievents namespace. As we can see here, it uses globalThi…

---

## [\`@JsExport object\` with ES-modules](https://discuss.kotlinlang.org/t/jsexport-object-with-es-modules/28106)

<div class="topic-metadata">

**Author:** [@bcwhite](https://discuss.kotlinlang.org/u/bcwhite)\
**Replies:** 0\
**Last updated:** [February 7, 2024, 11:31pm UTC](https://discuss.kotlinlang.org/t/jsexport-object-with-es-modules/28106 "2024-02-07T23:31:14Z")

</div>

I’m in the process of trying to switch to ES-modules for a common library that is used by my Angular application. package com.mydomain.myproj.common @JsExport object GlobalConstants { const val VERSION = "0.64.0" } …

---

## [Kotlin/NextJs - Webview loses input focus after typing](https://discuss.kotlinlang.org/t/kotlin-nextjs-webview-loses-input-focus-after-typing/28061)

<div class="topic-metadata">

**Author:** [@janhandy18](https://discuss.kotlinlang.org/u/janhandy18)\
**Replies:** 0\
**Last updated:** [January 30, 2024, 3:10pm UTC](https://discuss.kotlinlang.org/t/kotlin-nextjs-webview-loses-input-focus-after-typing/28061 "2024-01-30T15:10:10Z")

</div>

Hello and thank you for taking the time. I have built an application in NextJs. This is based on NodeJS in the backend and React in the front end. Since I would like to have the application in the Appstore, I thought “…

---

## [Confused about Promises or otherwise suspended functions](https://discuss.kotlinlang.org/t/confused-about-promises-or-otherwise-suspended-functions/27839)

<div class="topic-metadata">

**Author:** [@SvenWollinger](https://discuss.kotlinlang.org/u/SvenWollinger)\
**Replies:** 9\
**Last updated:** [December 24, 2023, 10:00am UTC](https://discuss.kotlinlang.org/t/confused-about-promises-or-otherwise-suspended-functions/27839 "2023-12-24T10:00:57Z")

</div>

Hey, i got a function that requests a json file from a server, which i figured out how to do in a blocking way thanks to coroutines. Im now in the situation where id like to have it assigned directly in a class, but tha…

---

## [How to transpile kotlin to ecmascript latest version?](https://discuss.kotlinlang.org/t/how-to-transpile-kotlin-to-ecmascript-latest-version/27635)

<div class="topic-metadata">

**Author:** [@anlexN](https://discuss.kotlinlang.org/u/anlexN)\
**Replies:** 0\
**Last updated:** [November 14, 2023, 4:51am UTC](https://discuss.kotlinlang.org/t/how-to-transpile-kotlin-to-ecmascript-latest-version/27635 "2023-11-14T04:51:54Z")

</div>

Kotlin for JavaScript The current implementation of Kotlin/JS targets ES5. I don’t like es5. I have clone kotlinx.coroutines. now kotlinx-coroutines-core.js is also es5. how to build ecmascript latest version by myse…

---

## [Configure JS devServer with custom headers](https://discuss.kotlinlang.org/t/configure-js-devserver-with-custom-headers/27263)

<div class="topic-metadata">

**Author:** [@Loke](https://discuss.kotlinlang.org/u/Loke)\
**Replies:** 0\
**Last updated:** [August 21, 2023, 5:10pm UTC](https://discuss.kotlinlang.org/t/configure-js-devserver-with-custom-headers/27263 "2023-08-21T17:10:43Z")

</div>

I’m building a web frontend for my multiplatform project, and as part of that I need to use the JS SharedArrayBuffer. When using this class in JS, you must have two specific headers set. If not, this class is not availab…

---

## [Is Kotlin + React discontinued?](https://discuss.kotlinlang.org/t/is-kotlin-react-discontinued/27075)

<div class="topic-metadata">

**Author:** [@H2k](https://discuss.kotlinlang.org/u/H2k)\
**Replies:** 4\
**Last updated:** [July 20, 2023, 8:56pm UTC](https://discuss.kotlinlang.org/t/is-kotlin-react-discontinued/27075 "2023-07-20T20:56:40Z")

</div>

I noticed that Kontlin/JS + React tutorial disappeared from the Kotlin homepage (at least I can’t find it anymore). Are there any news, if react support (kotlin wrappers) will be discontinued? Edit: Seems like one does…

---

## [Creating a custom element / webcomponent](https://discuss.kotlinlang.org/t/creating-a-custom-element-webcomponent/3988)

<div class="topic-metadata">

**Author:** [@dazraf](https://discuss.kotlinlang.org/u/dazraf)\
**Replies:** 15\
**Last updated:** [July 18, 2023, 8:27am UTC](https://discuss.kotlinlang.org/t/creating-a-custom-element-webcomponent/3988 "2023-07-18T08:27:43Z")

</div>

Hi, Has anyone figured out how to create a custom element? An example of this is documented here: Google developer docs and further documented here: Mozilla docs The principle is to call window.customElements.defin…

---

## [How to convert Typescript to Kotlin?](https://discuss.kotlinlang.org/t/how-to-convert-typescript-to-kotlin/26999)

<div class="topic-metadata">

**Author:** [@zhangruize44](https://discuss.kotlinlang.org/u/zhangruize44)\
**Replies:** 2\
**Last updated:** [June 29, 2023, 8:01am UTC](https://discuss.kotlinlang.org/t/how-to-convert-typescript-to-kotlin/26999 "2023-06-29T08:01:04Z")

</div>

Is it possible to translate typescript codes to kotlin codes? So that the kotlin codes can be compiled to classes and run on android devices with better performance than running original typescript on some JS engines. R…

---

## [Kotlin function references have no identity when compiled to JS (and have different semantics on JVM and JS platforms)](https://discuss.kotlinlang.org/t/kotlin-function-references-have-no-identity-when-compiled-to-js-and-have-different-semantics-on-jvm-and-js-platforms/9676)

<div class="topic-metadata">

**Author:** [@snorbi](https://discuss.kotlinlang.org/u/snorbi)\
**Replies:** 3\
**Last updated:** [June 27, 2023, 11:12am UTC](https://discuss.kotlinlang.org/t/kotlin-function-references-have-no-identity-when-compiled-to-js-and-have-different-semantics-on-jvm-and-js-platforms/9676 "2023-06-27T11:12:51Z")

</div>

Let’s have the following code: class TestClass { fun memberFunction() {} val memberFunctionReference get() = this::memberFunction } fun main(args: Array\<String\>) { val a = TestClass() println(a.memberF…

---

## [Small plugin for finding infinite loops](https://discuss.kotlinlang.org/t/small-plugin-for-finding-infinite-loops/26901)

<div class="topic-metadata">

**Author:** [@tothiz](https://discuss.kotlinlang.org/u/tothiz)\
**Replies:** 1\
**Last updated:** [June 13, 2023, 9:40pm UTC](https://discuss.kotlinlang.org/t/small-plugin-for-finding-infinite-loops/26901 "2023-06-13T21:40:20Z")

</div>

Hi! I’ve been trying to find an infinite loop in my own code in a Kotlin/JS + coroutines + messaging + reactivity project. As debugging coroutines is a pain, especially in a browser, I thought that it would be easier (…

---

## [Can I have several Output Files when using Kotlin JS](https://discuss.kotlinlang.org/t/can-i-have-several-output-files-when-using-kotlin-js/4266)

<div class="topic-metadata">

**Author:** [@rostei](https://discuss.kotlinlang.org/u/rostei)\
**Replies:** 3\
**Last updated:** [June 13, 2023, 3:27pm UTC](https://discuss.kotlinlang.org/t/can-i-have-several-output-files-when-using-kotlin-js/4266 "2023-06-13T15:27:33Z")

</div>

I recently started using Kotlin for a Chrome-Extension-Project. For this I need the kotlin js transpiler not to output just one js file with all the code in it, but two distinct files. Is there currently an option to do…

---

## [Unable to read properties from data object in Kotlin/JS](https://discuss.kotlinlang.org/t/unable-to-read-properties-from-data-object-in-kotlin-js/26897)

<div class="topic-metadata">

**Author:** [@cchunduri](https://discuss.kotlinlang.org/u/cchunduri)\
**Replies:** 2\
**Last updated:** [June 6, 2023, 8:57am UTC](https://discuss.kotlinlang.org/t/unable-to-read-properties-from-data-object-in-kotlin-js/26897 "2023-06-06T08:57:16Z")

</div>

Hello everyone, I am currently developing a Kotlin/JS application for an internal demo, and I’m using the fetch API to call a back-end service that provides weather information. I’ve written the following code to make t…

---

## [Setting environment variable with KotlinJS and Webpack 5](https://discuss.kotlinlang.org/t/setting-environment-variable-with-kotlinjs-and-webpack-5/26777)

<div class="topic-metadata">

**Author:** [@BugFactory](https://discuss.kotlinlang.org/u/BugFactory)\
**Replies:** 1\
**Last updated:** [May 6, 2023, 8:28pm UTC](https://discuss.kotlinlang.org/t/setting-environment-variable-with-kotlinjs-and-webpack-5/26777 "2023-05-06T20:28:01Z")

</div>

Hello, newcomer here. I’m learning KotlinJS, and I have a problem setting environment variables. 1. My requirement Basically, I want to set different variables such as the backend url depending on the environment (PROD…

---

## [How can I change Node.js version in Kotlin/JS project?](https://discuss.kotlinlang.org/t/how-can-i-change-node-js-version-in-kotlin-js-project/26648)

<div class="topic-metadata">

**Author:** [@marcel.svitalsky.gmail.com](https://discuss.kotlinlang.org/u/marcel.svitalsky.gmail.com)\
**Replies:** 4\
**Last updated:** [April 25, 2023, 7:09pm UTC](https://discuss.kotlinlang.org/t/how-can-i-change-node-js-version-in-kotlin-js-project/26648 "2023-04-25T19:09:37Z")

</div>

Hi there. I have an app written in Kotlin/React, and after upgrading Kotlin version from 1.8.10 to 1.8.20, I cannot compile it anymore, getting this error (with 1.8.10 it works OK): $HOME/.gradle/nodejs/node-v18.12.1-…

---

## [External Interface Required Fields](https://discuss.kotlinlang.org/t/external-interface-required-fields/26499)

<div class="topic-metadata">

**Author:** [@piacenti](https://discuss.kotlinlang.org/u/piacenti)\
**Replies:** 0\
**Last updated:** [March 8, 2023, 6:14pm UTC](https://discuss.kotlinlang.org/t/external-interface-required-fields/26499 "2023-03-08T18:14:49Z")

</div>

When using Kotlin JS with libraries such as react, you may frequently create external interfaces for react props you want to use. They have to be external interfaces because they extend the external interface Props and K…

---

## [Implementing a WebWorker in Kotlin](https://discuss.kotlinlang.org/t/implementing-a-webworker-in-kotlin/3892)

<div class="topic-metadata">

**Author:** [@ConnyOnny](https://discuss.kotlinlang.org/u/ConnyOnny)\
**Replies:** 13\
**Last updated:** [February 25, 2023, 10:42am UTC](https://discuss.kotlinlang.org/t/implementing-a-webworker-in-kotlin/3892 "2023-02-25T10:42:03Z")

</div>

The JavaScript worker API is exposed to Kotlin and I can easily create web workers with it. Can I also write the worker’s code in Kotlin?

---

## [New test run in Kotlin/JS](https://discuss.kotlinlang.org/t/new-test-run-in-kotlin-js/26428)

<div class="topic-metadata">

**Author:** [@simonjacobs](https://discuss.kotlinlang.org/u/simonjacobs)\
**Replies:** 0\
**Last updated:** [February 24, 2023, 11:34am UTC](https://discuss.kotlinlang.org/t/new-test-run-in-kotlin-js/26428 "2023-02-24T11:34:02Z")

</div>

Has anyone successfully created a project where they have a separate JS compilation and test run using it? I’m using the IR compiler in a multiplatform project, if that makes any difference. At first it seems like the w…

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