https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
javascript
  • a

    Ansh Tyagi

    11/15/2021, 5:57 PM
    hey everyone! I was fidgeting around kotlin/js and wanted to know if there is some easy way around to do this:
    override fun RBuilder.render() {
            div {
                div(){}
                div(){}
                div(){}
                div(){}
                div(){}
                div(){}
                div(){}
                div(){}
                div(){}
                div(){}
            }
        }
    is there any way around like
    List.generate()
    something that sort of in kotlin or can we use
    map
    function?
    t
    • 2
    • 1
  • m

    martmists

    11/15/2021, 7:25 PM
    Is there a way to force Kotlin/JS to generate classes as classes rather than as functions? It causes errors when extending an external JS-defined class
    t
    • 2
    • 1
  • a

    Ansh Tyagi

    11/16/2021, 9:15 AM
    How to import css in kotlin multiplatform(only targeted for js right now). I tried adding a css file in in the
    jsMain/kotlin
    and used
    kotlinext.require
    but it the build throws an error of module not found in
    jsBrowserProductionWebpack
    i used the template for fullstack web app from idea i think it enables cssSupport by default as specified in the docs. Is it that i have to specify the file path under gradle as well or do i have to change the location of the css?
    b
    • 2
    • 3
  • a

    ankushg

    11/16/2021, 8:32 PM
    When using the JS IR compiler backend with the
    "-Xir-per-module"
    flag, we get separate files (which is great!) For local project dependencies, we get filenames like
    ${rootProject.name}-{project.name}.js
    . From a Maven artifact like
    org.jetbrains.kotlinx:kotlinx-serialization-core
    , we get
    kotlinx-serialization-kotlinx-serialization-core.js
    I’m assuming the
    kotlinx-serialization
    prefix is because that's also the
    rootProject.name
    in the
    kotlinx.serialization
    repo (and this lines up with the other artifacts). But I can't figure out how to get that prefix programatically. Instead, I'm stuck hardcoding values for all our external dependencies. Is there a way to get that prefix for a Kotlin/JS maven artifact within Gradle? If there isn't a way to get that prefix programatically, using
    rootProject.name
    (instead of
    group
    ) makes it really hard to interact with those files in an automated fashion…
    👍 2
    ➕ 3
    • 1
    • 1
  • k

    Kevin Luo

    11/16/2021, 9:00 PM
    Hi, i updated my project recently to kotlin 1.5 but I am now having issues with the
    react-dom
    library. I can't set the
    ref
    attribute for my react components, since it no longer allows passing lambdas to
    attrs.ref
    .
    var myRef : Element? = null
    
    styledDiv {
      attrs.ref {
        myRef = it as? Element
      }
    }
    So the above code no longer works. Is there a workaround for this?
    ✅ 1
    t
    • 2
    • 2
  • j

    Jeff Lockhart

    11/17/2021, 1:16 AM
    I'm experiencing an odd error I ran into converting some react classes to functional components. Replacing my code with even a couple simple FCs, I'm still getting this unexpected error:
    Uncaught TypeError: $this$child._get_attrs__0_k$()._set_baz__qlpr75_k$ is not a function
    .
    fun main() {
        render(document.getElementById("root")) {
            child(app)
        }
    }
    
    val app = fc<Props> {
        child(foo) {
            attrs.baz = "test"
        }
    }
    
    interface Bar : Props {
        var baz: String
    }
    
    val foo = fc<Bar> { props ->
        +props.baz
    }
    It's erroring on the line
    attrs.baz = "test"
    . Am I doing something wrong? I'm using version
    17.0.2-pre.265-kotlin-1.5.31
    of the Kotlin React wrappers.
    ✅ 1
    • 1
    • 1
  • c

    Carson Holzheimer

    11/17/2021, 2:18 PM
    I tried to add dukat generation for a library, but when I build, nothing happens and the
    build/externals
    folder is basically empty. This is in a multiplatform project
    val jsMain by getting {
                dependencies {
                    implementation(npm("fabric", "4.5.0"))
                    implementation(npm("@types/fabric", "4.5.0", generateExternals = true))
                }
            }
    t
    • 2
    • 4
  • c

    Carter

    11/17/2021, 6:18 PM
    Bumping my Kotlin version from 1.5.31 to 1.6 in a Multiplatform JS project seems to hit an Apple Silicon related build error. I’ll be able to test on an Intel Mac to confirm whether it is an ARM v Intel issue, but it seems likely based on the URL.
    Could not determine the dependencies of task ':kotlinNodeJsSetup'.
    > Could not resolve all files for configuration ':detachedConfiguration2'.
       > Could not find node-14.17.0-darwin-arm64.tar.gz (org.nodejs:node:14.17.0).
         Searched in the following locations:
             <https://nodejs.org/dist/v14.17.0/node-v14.17.0-darwin-arm64.tar.gz>
    In the meantime, has anyone else run into this or is there a workaround?
    g
    h
    • 3
    • 6
  • m

    Mihai Voicescu

    11/17/2021, 6:45 PM
    I have 2 sub-projects 1. Generates the JS/HTML/CSS files browserDistribution task 2. Backend server that needs the generated output of browserDistribution inside his resources to server them static How can I instruct gradle to do this 🙂 ?
    c
    • 2
    • 2
  • a

    ankushg

    11/17/2021, 8:23 PM
    We've been using gradle-node-plugin in our project to write Gradle Tasks that call node/npm because it • lets us explicitly specify an npm version • lets us share tasks across projects that don't use Kotlin/JS • has convenient helpers for
    NpmTask
    and
    NpxTask
    • seems to be better-documented than the almost-secret tasks bundled with Kotlin/JS At the same time, the Kotlin/JS compiler also downloads node/yarn as needed too. Does anyone have a setup where they have them configured to play well together? Maybe just • turning off downloads for one of the two plugins • setting them both to run yarn from the same directory • making sure that the setup task for the plugin with the disabled download dependsOn the setup task for the other plugin ?
    m
    e
    • 3
    • 5
  • a

    ankushg

    11/18/2021, 7:30 AM
    In the new JS IR, is there a Kotlin type (or an
    external interface
    definition) that gets exported as a JS/TS
    Map
    with specific key/value types?
    b
    s
    • 3
    • 24
  • a

    Ansh Tyagi

    11/18/2021, 9:35 AM
    How can one add Google Fonts(i want to do Poppins lets say) to KotlinJS. I couldnt find any link tag that could be added to import the fonts. I am using Kotlin MPP.
    b
    b
    • 3
    • 9
  • a

    Ayfri

    11/18/2021, 6:47 PM
    Is there any new plans for Dukat in Kotlin 1.6 ?
    👍 1
    v
    t
    • 3
    • 5
  • a

    ankushg

    11/18/2021, 11:29 PM
    Is it possible/planned to
    @JsExport
    a
    typealias
    ? Have some complicated types that I'd love to be able to provide more readable names to in my .d.ts file
    ➕ 2
    b
    • 2
    • 4
  • a

    Ayfri

    11/20/2021, 10:56 PM
    Hi, can someone explain me how to transform a project of mine which adds typings of a JS library into a Kotlin library, I don't know anything about publishing library or even making a project a library.
    t
    • 2
    • 5
  • h

    hfhbd

    11/21/2021, 10:56 AM
    Should I use
    enum
    or an
    interface
    with inline functions and
    unsafeCast
    to reduce binary size?
    t
    a
    • 3
    • 16
  • a

    altavir

    11/23/2021, 2:49 PM
    I am seeing new type of error on JS-IR on 1.6
    > Task :visionforge-solid:compileTestDevelopmentExecutableKotlinJs FAILED
    e: org.jetbrains.kotlin.backend.common.serialization.linkerissues.IrDisallowedErrorNode: Class found but error nodes are not allowed.
    	at org.jetbrains.kotlin.backend.common.serialization.IrDeclarationDeserializer.deserializeErrorType(IrDeclarationDeserializer.kt:840)
    Have anyone seen something like this?
    r
    e
    • 3
    • 5
  • m

    MrPowerGamerBR

    11/23/2021, 3:20 PM
    How can I include a svg in my Kotlin/JS resources? I followed this (https://kotlinlang.slack.com/archives/C0B8L3U69/p1637057339393600?thread_ts=1637054144.390200&amp;cid=C0B8L3U69) but that only seems to include the file in the webserver, instead of embedding it in the JS file.
    @JsModule("./star.svg")
    @JsNonModule
    external val star: dynamic
    console.log(star)
    =
    <http://localhost:8080/images/8879ae8fb00946dae2fd.svg>
    , instead of printing the svg content. I want the svg to be inlined (because animations) so that's why I can't just reference the svg in a <img> tag
    t
    f
    • 3
    • 10
  • f

    fkrauthan

    11/24/2021, 5:22 AM
    Hey I am trying to configure the
    WebpackManifestPlugin
    and
    HtmlWebpackPlugin
    but are wondering where the webpack file is gonna be generated in and how I can point to files in
    build/processedResources/js/main
    ? Also is there any way in my
    webpack.config.d
    files to have a condition depending on if its a dev build vs a prod build? I couldn't find any obvious flag I could use
    t
    • 2
    • 2
  • a

    andylamax

    11/24/2021, 5:14 PM
    Hello there, I have upgraded (from 1.5.31 to 1.6.0) somewhat a big multiplatform project with multi modules having jvm and js targets only. I am currently getting this error when I try to compile to kotlin/js.
    > Task compileKotlinJs FAILED
    e: Could not find "kotlin" in [/home/andylamax/.local/share/kotlin/daemon]
    e: java.lang.IllegalStateException: Could not find "kotlin" in [/home/andylamax/.local/share/kotlin/daemon]
            at org.jetbrains.kotlin.cli.js.K2JsIrCompilerKt$messageCollectorLogger$1.fatal(K2JsIrCompiler.kt:539)
            at org.jetbrains.kotlin.library.KotlinLibrarySearchPathResolver.resolve(SearchPathResolver.kt:175)
    It should be also be known that task compileKotlinJvm executes successfully. What might the problem be?
    • 1
    • 1
  • h

    hfhbd

    11/24/2021, 6:03 PM
    What are the downsides if you dont call
    binaries.executable()
    or
    binaries.library()
    in your gradle config?
    a
    b
    s
    • 4
    • 7
  • a

    andylamax

    11/25/2021, 1:58 AM
    Back again, after downgrading back to 1.5.31 from 1.6.0, I am know getting
    > Task :compileDevelopmentExecutableKotlinJs FAILED
    e: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.collections.CollectionsKt___CollectionsKt.joinToString, parameter $this$joinToString
            at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt)
            at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:3360)
            at org.jetbrains.kotlin.ir.util.RenderIrElementVisitor.visitClass(RenderIrElement.kt:467)
    Has anyone seen this?? compileKotlinJs does execute successfully. Help??
    g
    • 2
    • 2
  • s

    Slackbot

    11/25/2021, 1:46 PM
    This message was deleted.
    s
    h
    • 3
    • 8
  • m

    MrPowerGamerBR

    11/26/2021, 2:34 AM
    I wonder if anyone already found this bug, because I wouldn't find anything related to this in YouTrack or in this channel
    println("Test: ${"297153970613387264".toLong()}")
    prints...
    Test: 297153970613387260
    Only happens with the IR compiler, not with the Legacy compiler, I actually thought this was a kotlinx.serialization bug until I tried debugging it further to find out that it is actually Kotlin that is having the issue! 😭 Tested in Kotlin 1.5.31, haven't tested in Kotlin 1.6.0 yet because Jetpack Compose Web doesn't support Kotlin 1.6.0... yet!
    e
    a
    • 3
    • 9
  • p

    Pavel Matusevich

    11/28/2021, 12:19 AM
    Hello. I'm trying to make a Ring UI Table mappings for Kotlin. There is a class named "Selection". It contains set of selected items (which is represented by JS class Set). However, when I tried to map it like that:
    fun getSelected(): Set<RowData>
    fun getActive(): Set<RowData>
    and then trying to access this set using
    for (selected in selection.getSelected()){..}
    in browser it throws
    Uncaught TypeError: it.getSelected().iterator is not a function
    . By looking at Kotlin/JS documentation I see that Kotlin collections does not map to any specific class in JS ("Kotlin collections (
    List
    ,
    Set
    ,
    Map
    , and so on) are not mapped to any specific JavaScript type."). So, my question: is it okay to publish mapping like that or is there a better way to do that mapping? (like custom Set class, or anything else...)
    b
    t
    • 3
    • 6
  • s

    smallshen

    11/28/2021, 8:36 PM
    is it possible that we use vitejs instead of webpack?
    b
    • 2
    • 1
  • h

    hfhbd

    11/29/2021, 8:04 AM
    Anybody else having build errors using 1.5.31 and consuming a JS Kotlin library build with 1.6.0? https://youtrack.jetbrains.com/issue/KT-49959
    t
    • 2
    • 4
  • p

    Pavel Matusevich

    11/29/2021, 9:22 PM
    Hello. How can I implement "thisArg" (Value to use as
    this
    when executing
    callback
    ) from JS Set? My current implementation is
    @JsName("Set")
    external class JsSet<T> {
    ...
    fun <A> forEach(callback: (value: T, key: T, set: JsSet<T>, thisArg: A) -> Unit, thisArg: A)
    ...
    }
    However, when calling this function
    forEach({ key, value, set, thisArg ->
                                console.log("1", key, "2", value, "3", set, thisArg)
                            }, "thisArgValue")
    thisArg is
    undefined
    , when it should be
    "thisArgValue"
    Thanks.
    t
    • 2
    • 1
  • f

    Franco

    11/30/2021, 9:36 PM
    Hey everyone, out of nowhere I started getting the following error today:
    Could not determine the dependencies of task ':kotlinNodeJsSetup'.
    You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
    > Could not resolve all files for configuration ':detachedConfiguration3'.
    
       > Could not resolve org.nodejs:node:14.17.0.
         Required by:
             project :
          > Could not resolve org.nodejs:node:14.17.0.
             > Could not get resource '<https://kotlin.bintray.com/kotlinx/org/nodejs/node/14.17.0/node-14.17.0.pom>'.
                > Could not GET '<https://kotlin.bintray.com/kotlinx/org/nodejs/node/14.17.0/node-14.17.0.pom>'. Received status code 502 from server: Bad Gateway
    Anyone know what's happening?
    m
    • 2
    • 20
  • n

    Nicodemus Ojwee

    12/01/2021, 12:19 PM
    Hello, Do we have the following functions in KotlinJS. If so, which is the appropriate way of using them? • unescape() • decodeURI() • decodeURIComponent() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape
    a
    r
    • 3
    • 2
Powered by Linen
Title
n

Nicodemus Ojwee

12/01/2021, 12:19 PM
Hello, Do we have the following functions in KotlinJS. If so, which is the appropriate way of using them? • unescape() • decodeURI() • decodeURIComponent() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/unescape
a

andylamax

12/01/2021, 12:24 PM
if not available in the stdlib, define them as external functions
👍 1
r

Robert Jaros

12/01/2021, 12:31 PM
https://youtrack.jetbrains.com/issue/KT-22277
👍 2
View count: 4