https://kotlinlang.org logo
Join Slack
Powered by
# javascript
  • a

    Alex Styl

    06/12/2025, 6:13 AM
    can i somehow magically use the typescript types from npm libraries? ie I use the
    stripe
    package. do i need to create my own external interfaces(or use with dynamic) every time?
    e
    • 2
    • 1
  • l

    Luv Kumar

    06/13/2025, 7:53 PM
    Hi all, i am trying to find a way to export suspend function for js target, i have gone through multiple resources online but i am not able to find a way to do that the way i want. I want that
    suspend fun foo(): String
    should get converted to
    foo(): Promise<string>;
    in Js. From what i know there is no native support for this. I was able to reach a Js signature
    fooAsync(): Promise<String>;
    using kotlin-suspend-transform-compiler-plugin , but i would want to have the same signature(without async) as it would be easier for all 3 targets(android, ios and js) to follow the generated docs and use it. Is there a way to achieve this ? other obv option is to have duplicate exported api interfaces for only js, but i really don't wish to go that route. I was also thinking if this plugin or some other plugin could help me generate a synthetic function
    Copy code
    @JsExport
    @JsName("foo")
    fun fooSynthetic(): Promise<String> // generated synthetic function
    
    @JsName("_foo")
    suspend fun foo(): String // original function defined in api
    If somehow above could be achieved, i was thinking it could work ? (Please correct me if my thought process is wrong here, i am new to KMP) Thanks.
    e
    • 2
    • 3
  • s

    shikhar

    06/15/2025, 3:33 AM
    How does one actually enable this? https://kotlinlang.org/docs/whatsnew20.html#suspend-functions-as-es2015-generators Couldn’t find any docs. Is it enabled by default when we set compilation target to es2015?
    e
    • 2
    • 1
  • r

    Remy Benza

    06/16/2025, 8:05 AM
    is there a kotlin js wrapper for framer motion or something else to get easy list animations (delete / insert of items) without writing much code myself
    a
    t
    • 3
    • 7
  • g

    Genis Lin

    06/16/2025, 1:14 PM
    Hi, I’m Genis, a 3D developer specializing in immersive web and interactive experiences. I leverage cutting-edge tools like: Three.js, Babylon.js → High-performance WebGL & 3D web apps Cesium, Mapbox → Geospatial & real-time 3D mapping Unity 3D → Games, simulations, AR/VR With 7+ years of experience, I build visually stunning, scalable solutions for clients worldwide. Check out my work: 👉 Portfolio: https://kakao-3d.vercel.app/ Let’s collaborate! Open to freelance projects, contract roles, or innovative partnerships. #3DDevelopment #Three.js #WebGL #Unity3D #GameDev #TechArt
    not kotlin but kotlin colored 6
    c
    • 2
    • 1
  • e

    Edoardo Luppi

    06/16/2025, 6:47 PM
    @broadway_lamb regarding the Clojure Compiler discussion, and the fact the JS code has to be parsed and potentially lowered to older targets, what about using the TS compiler API? It's just a random idea, but it gives you a visitable AST + the ability to downlevel by compiling it. Yes, you'll have to implement a separate program (and exchange data with it, e.g. via a pipe?) to translate TS AST to something you can read in Kotlin, spawn a separate process, but it doesn't seem totally crazy. With
    tsgo
    this might become even easier as it won't require a Node instance to be running.
    b
    • 2
    • 3
  • p

    PHondogo

    06/18/2025, 8:46 PM
    How to check if code is running in test mode (unit test)?
    e
    • 2
    • 4
  • p

    phteven

    06/19/2025, 11:06 AM
    How can I dynamically link resources to my index.html via webpack? https://kotlinlang.org/docs/running-kotlin-js.html#run-the-browser-target Only shows hardcoded strings for the generated js file. When i want to use the webpack content hash for example, what is the best way to implement this?
    outputFileName = “main.bundle-[contenthash].js”
    c
    • 2
    • 3
  • v

    Volodymyr Galandzij

    06/19/2025, 6:25 PM
    What’s the current status of Automatic generation of Kotlin wrappers from TypeScript typings mentioned in https://blog.jetbrains.com/kotlin/2025/05/present-and-future-kotlin-for-web/ ? Is there a ticket to track the progress at YouTrack or GitHub?
    e
    s
    • 3
    • 2
  • h

    Hildebrandt Tobias

    06/19/2025, 9:34 PM
    Hey, I have a small Problem with TanStackQuery. The options that expect functions don't work.
    Copy code
    useQuery<Array<DocumentationElementDto>?, Error, Array<DocumentationElementDto>, QueryKey>(
        options = UseQueryOptions(
            queryKey = DOCUMENTATION_QUERY_KEY.plus(subCategory),
            queryFn = QueryFunction { 
                secureApi(DocumentationEndpoints
                    .getDocumentationElement
                    .copy(optionalQueryParams = pairListOf("category" to subCategory))
            )},
            refetchOnMount = { _ -> false },
            refetchOnWindowFocus = { _ -> false },
            refetchOnReconnect = { _ -> false },
            refetchInterval = 0,
            refetchIntervalInBackground = false,
        )
    )
    In this case
    Copy code
    refetchOnMount = { _ -> false },
    refetchOnWindowFocus = { _ -> false },
    refetchOnReconnect = { _ -> false },
    doesn't work, but these two:
    Copy code
    refetchInterval = 0,
    refetchIntervalInBackground = false,
    behave as expected. I also tried
    useCallback { _ -> false }
    , but it isn't accepted by the compiler.
    t
    • 2
    • 5
  • m

    Martin Janči

    06/22/2025, 2:38 PM
    I am using multiple kotlinjs in one project. Problem is, yarn is in root project and it is shared. thats makes conflicts, because of overwriting. Is there smart way to handle this?
    h
    • 2
    • 3
  • h

    Hildebrandt Tobias

    06/24/2025, 8:44 PM
    Hey, I have a problem with the google maps api and the predefined marker symbols. I looked at this this and I use
    <http://vis.gl/react-google-maps|vis.gl/react-google-maps>
    , but I also loaded
    googlemaps/js-api-loader
    . If you look at the Marker example there is:
    Copy code
    new google.maps.Marker({
        position: map.getCenter(),
        icon: {
          path: google.maps.SymbolPath.CIRCLE,
          scale: 10,
        },
        draggable: true,
        map: map,
      });
    But I can't figure out how to aquire the predefined
    google.maps.SymbolPath.CIRCLE
    constant? object? Just providing the path as a string doesn't work it says unexpected g at position 0 (the g from google I guess). I tried
    Copy code
    @file:JsModule("@googlemaps/js-api-loader")
    @file:JsNonModule
    
    package shared.utils.maps
    
    @JsName("CIRCLE")
    external val CIRCLE: dynamic
    But that also doesn't work. I know I can provide my own SVG and PNG and such, but it kinda irks me, someone got an idea? Edit: Okay I added the npm https://www.npmjs.com/package/google-maps and added:
    Copy code
    @file:JsModule("google-maps")
    @file:JsNonModule
    
    package shared.utils.maps
    
    @JsName("CIRCLE")
    external val CIRCLE: dynamic
    But it seems that
    CIRCLE
    is
    null
    when I access it.
    a
    • 2
    • 9
  • h

    Hildebrandt Tobias

    06/25/2025, 9:07 PM
    Are singletons not allowed anymore? I updated to
    2025.6.11
    and now I get
    Copy code
    org.jetbrains.kotlin.util.FileAnalysisException: While analysing Authentication.kt:47:1: org.jetbrains.kotlin.utils.exceptions.KotlinIllegalArgumentExceptionWithAttachments: Exception in declaration checker
    
    Caused by: java.lang.IllegalStateException: Symbol for Any not found
    For every top level
    object
    declaration like
    Copy code
    object Foo {
      val bar: Bar
    }
    where there is no
    Any
    ? EDIT Okay I cleaned and invalidated everything and it doesn't come up for now. I'll check back once the migration is fixed. Edit2 I get the error with Kotlin 2.1.0, but not with 2.2.0, but migrating to 2.2.0 is much work now. sigh.
    c
    t
    • 3
    • 4
  • c

    CLOVIS

    06/27/2025, 8:55 PM
    Vite for Kotlin 0.5.2 is released, and it finally supports Kotlin 2.1.0+! https://opensavvy.gitlab.io/automation/kotlin-vite/api-docs/
    👍 2
    🔥 2
    👀 2
    👍🏾 1
  • s

    Sargun Vohra

    07/01/2025, 5:16 PM
    I have a KMP library with a JS library export. My Kotlin declarations are namespaced in JS so for example the user has to do:
    Copy code
    const { PokeApi } = require('pokekotlin').co.pokeapi.pokekotlin
    Is there any way to override that namespacing so JS users can use my library like:
    Copy code
    const { PokeApi } = require('pokekotlin')
    Or alternatively, is there a way to include some custom js and .d.ts in my Kotlin/JS library export? So I can define an index.js myself that re-exports my declarations from the root My goal is to have a single KMP library with an idiomatic API for Kotlin, Java, JS/TS, and Swift/ObjC, but the package name being exposed to JS is awkward there. It’s more than just the import syntax; LSP tooling like automatic imports and stuff don’t work well when the importable declarations are buried under a package hierarchy.
    e
    • 2
    • 3
  • c

    CLOVIS

    07/05/2025, 5:27 PM
    How do sourcemaps work? If I create a simple project and run
    jsBrowserDevelopmentRun
    , I get: •
    build/js/packages/example-simple/kotlin/example-simple.js
    •
    build/js/packages/example-simple/kotlin/example-simple.js.map
    The second one contains:
    Copy code
    {
    	"version": 3,
    	"sources": [
    		"../../../../../src/jsMain/kotlin/Main.kt",
    		"../../../../compileSync/js/main/developmentExecutable/kotlin/src/kotlin/util/Standard.kt"
    	],
        // …
    The
    Main.kt
    file refers to my own source code, fine. However, I don't understand that
    Standard.kt
    file. The
    build/compileSync/js/main/developmentExecutable/kotlin
    folder does NOT contain a
    src/
    folder, and there is no
    Standard.kt
    file anywhere in the
    build/
    directory. What's going on here?
    👍 1
    l
    e
    • 3
    • 5
  • z

    Zyle Moore

    07/06/2025, 12:45 AM
    While running jsBrowserProductionWebpack, some of the modules generate with warnings. How can I see what those warning are?
    Copy code
    > Task :web:jsBrowserProductionWebpack
    asset web.js 221 KiB [emitted] [minimized] (name: main) 2 related assets
    modules by path ../../node_modules/ 539 KiB
      modules by path ../../node_modules/react-dom/ 512 KiB 4 modules
      modules by path ../../node_modules/react/ 16.9 KiB
        ../../node_modules/react/index.js 186 bytes [built] [code generated]
        ../../node_modules/react/cjs/react.production.js 16.7 KiB [built] [code generated]
      modules by path ../../node_modules/scheduler/ 10.1 KiB
        ../../node_modules/scheduler/index.js 194 bytes [built] [code generated]
        ../../node_modules/scheduler/cjs/scheduler.production.js 9.94 KiB [built] [code generated]
    modules by path ./kotlin/*.js 158 KiB
      ./kotlin/prison-web.js 16.2 KiB [built] [code generated] [3 warnings]
      ./kotlin/kotlin-kotlin-stdlib.js 124 KiB [built] [code generated] [64 warnings]
      ./kotlin/kotlin-react.js 2.92 KiB [built] [code generated] [5 warnings]
      ./kotlin/kotlin-react-core.js 6.69 KiB [built] [code generated] [6 warnings]
      ./kotlin/prison-core.js 3.82 KiB [built] [code generated]
      ./kotlin/kotlin-react-dom.js 4.5 KiB [built] [code generated] [6 warnings]
    webpack 5.94.0 compiled successfully in 4535 ms
    a
    • 2
    • 1
  • s

    Sargun Vohra

    07/08/2025, 12:44 AM
    If I have a Kotlin/JS library with a dependency on an NPM module, is that NPM module passed on as a transient dependency to my consumers, or do those library consumers also have to include the
    npm(..)
    entry in their gradle file?
    r
    • 2
    • 1
  • m

    Marc

    07/08/2025, 2:10 PM
    I have a problem where I am writing a multiplatform library, but marking classes with
    @JsExport
    only works on classes that exclusively use non-suspending functions. Is there a way to transform the suspending functions into functions returning promises automatically? In case I need to do it manually I am also not quite sure how to do that, since I want to mostly keep the existing class but only transform a couple of suspending functions to promises.
    b
    e
    • 3
    • 11
  • a

    alexandre mommers

    07/09/2025, 5:26 PM
    Could anyone provide feedback or articles on how to profile Kotlin code running in a browser environment?
    e
    • 2
    • 1
  • m

    Mateus Moreira

    07/11/2025, 1:23 AM
    Hey, I was wondering if it is possible to publish have Kotlin/Js project for node so it's accessible through Typescript, the usage is simple, I have serializable classes in the backend and being able to re-use it in the frontend (react) without needing to re-make them in Typescript would be awesome.
    e
    • 2
    • 4
  • a

    Abduqodir Qurbonzoda

    07/11/2025, 9:38 AM
    Hey everyone! I'm encountering an error (
    No matching export in "<kmp-library>.mjs" for import "KtList"
    ) when I switch to ES2015 target. The issue is also described in this ticket. Is there any workaround for it?
    e
    • 2
    • 4
  • n

    Nathan Fallet

    07/12/2025, 3:11 PM
    Any idea why kotlinx-browser is available for wasm js but not for js ir?
    r
    m
    +2
    • 5
    • 10
  • c

    CLOVIS

    07/12/2025, 6:30 PM
    With Kotlin 2.2.0 I'm seeing a ton of
    Copy code
    > Task :kotlinNpmInstall FAILED
    error <https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-4.2.2.tgz>: Extracting tar content of undefined failed, the file appears to be corrupt: "ENOENT: no such file or directory, open '/usr/local/share/.cache/yarn/v6/npm-webpack-merge-4.2.2-a27c52ea783d1398afd2087f547d7b9d2f43634d-integrity/node_modules/webpack-merge/lib/join-arrays.js.map'"
    across all my projects, across all CI runners, with different packages. Do we know what could cause this? At the moment, it's hard to upgrade because all JS pipelines fail more than ~50% of the time
    r
    t
    +3
    • 6
    • 25
  • l

    Lucy

    07/14/2025, 6:14 PM
    Hi everyone waving from afar right I'm looking for more information on the JetBrains Kotlin-wrapper library. Does anyone have experience working with this library, especially the wrappers for kotlin-react or kotlin-react-dom? It seems that the latest versions require Kotlin 2.2.0, but I cannot find this info in the changelogs. I would like to use this library, but since I cannot find version compatibility info or any official communication channels, I am worried about maintainability.
    t
    • 2
    • 5
  • z

    Zyle Moore

    07/15/2025, 5:33 AM
    I'm intermittently receiving this issue in Intellij IDEA Community. It seemed to start happening after switching to Kotlin 2.2.0. It's not too intrusive yet, since rerunning the
    jsBrowserDevelopmentRun
    task usually works. I'm nowhere near max RAM on on my box though, this happens when usage is at < 30%. No noticeable increase in usage before or after.
    Copy code
    java.lang.OutOfMemoryError: GC overhead limit exceeded
    	at java.base/java.util.ArrayList.iterator(ArrayList.java:1029)
    	at org.jetbrains.kotlin.backend.common.linkage.partial.PartiallyLinkedIrTreePatcher$DeclarationTransformer.rewriteTypesInFunction(PartiallyLinkedIrTreePatcher.kt:1397)
    	at org.jetbrains.kotlin.backend.common.linkage.partial.PartiallyLinkedIrTreePatcher$DeclarationTransformer.visitSimpleFunction(PartiallyLinkedIrTreePatcher.kt:293)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitSimpleFunction(IrElementTransformerVoid.kt:131)
    	at org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid.visitSimpleFunction(IrElementTransformerVoid.kt:19)
    	at org.jetbrains.kotlin.ir.declarations.IrSimpleFunction.accept(IrSimpleFunction.kt:39)
    	at org.jetbrains.kotlin.ir.IrElementBase.transform(IrElementBase.kt:33)
    	at org.jetbrains.kotlin.ir.declarations.IrProperty.transformChildren(IrProperty.kt:55)
    ...
    a
    • 2
    • 2
  • h

    Hildebrandt Tobias

    07/15/2025, 8:45 AM
    Hey, I have a Problem with TanStackQuery and TanStackTables, When I receive an
    Array
    through
    useQuery<Array<MyType>>()
    and feed it into the TanStackTable directly everyting works, no problems. But when I filter the
    Array
    or convert it to a list for other reasons and then convert it back via
    .toTypedArray()
    the TanStackTable displays the data correctly, but it refreshes infinitely and very fast lagging the tab. I can see the constant
    getXXXModel()
    log messages in the console.
    Copy code
    previewDataQuery
      .data
      ?.filter { it.active }
      ?.toTypedArray()
    Someone got a suggestion how to fix this? Edit: So the behaviour is essentially like this:
    Copy code
    useReactTable(data = previewData) // OK
    useReactTable(data = previewData.toList().toTypedArray()) // Infinite Loop
    • 1
    • 1
  • e

    Edoardo Luppi

    07/16/2025, 9:55 AM
    Looks like the
    BigInt
    adoption in place of a custom
    Long
    implementation will be very useful for kotlinx-io, or for the UUID/hex stdlib utilities, as they make use of longs quite often.
    💯 5
    c
    • 2
    • 7
  • s

    shikhar

    07/16/2025, 4:03 PM
    for sure :), was stuck with this problem for providing common types in a library on all 3 targets (js, ios, android) And KMP messes it up for Long types in JS, as generated code and .d.ts mapped it to
    any
    type solved it like below:
    // common
    expect class NativeLong
    expect fun toNativeLong(value: Long): NativeLong
    actual fun toKtLong(value: NativeLong): Long
    // js
    actual typealias NativeLong = BigInt
    actual fun toNativeLong(value: Long) = (js("BigInt") as (dynamic) -> BigInt)(value.toString())
    actual fun toKtLong(value: NativeLong) = value.toString().toLong() // throws if out-of-range
    // ios/android
    actual typealias NativeLong = Long
    actual fun toNativeLong(value: Long): NativeLong = value
    actual fun toKtLong(value: NativeLong): Long = value
    And if it’s used in a
    @Serializable
    class, we provide a custom serializer based on target platform Now I can use it as:
    data class UserId(id: NativeLong)
    fun takeInput(value: NativeLong)
    And its easily usable for js devs
    // generated .d.ts
    export declare class UserId {
    constructor(id: BigInt);
    get id(): BigInt;
    copy(id?: BigInt): UserId;
    toString(): string;
    hashCode(): number;
    equals(other: Nullable<any>): boolean;
    }
    export declare function takeInput(num: BigInt): void;
    The primary downside here is overhead of
    toKtLong()
    in js, which decodes->encodes the value on every call. Solvable using a “holder” type for native values, which has a lazy prop that holds the kotlin long value. For folks who have tackled this, please suggest your methods and any issues you see with above. (like if using typealiasing like this has any risks for exported types etc)
    t
    • 2
    • 2
  • e

    Edoardo Luppi

    07/17/2025, 2:47 PM
    This is just me arbitrarily assuming things, so I might be completely wrong. With the incoming transition to using an external JS downleveling tool (e.g., SWC, Babel, etc.), the K/JS compiler backend could be simplified as it doesn't have to consider many options related to the ES targets anymore, or related to the module systems. That is, the compiler could simply emit ESM ES20xx code and delegate the translation to CJS/UMD/etc. and older ES versions to the external tool. This also means if Kotlin sets some baseline options (e.g., ESM + ES2020), and the developer doesn't need to change that baseline, the external tool could be skipped entirely. Theoretically it means compilation speed, especially during development, could get a lot better. Edit: tho I'm still ignorant about how the TS type declaration generation will be reshaped.
    👀 1
    a
    • 2
    • 7