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
  • j

    Jakob K

    05/27/2022, 3:16 PM
    The
    IR
    compiler is able to generate separate files for each module, but it seems like the distribution generated by
    jsBrowserDistribution
    still produces a single large file. How can I generate a distribution with modularized output files (like they are generated in
    build/compileSync/main/productionExecutable/kotlin/
    for example)?
    t
    1 reply · 2 participants
  • k

    Kashismails

    05/31/2022, 1:28 PM
    Hey guys I am looking for a sample kmp project with react if anyone can share some git repositories will be very helpful
    r
    4 replies · 2 participants
  • h

    hfhbd

    05/31/2022, 7:13 PM
    Hey, I have a Kotlin lib which exports a CSS file (bootstrap.css) by using
    webpackTask { cssSupport.enabled = true }
    in the library (bootstrap-compose) as well as in the consumer project. Executing a full build or just browserWebpack creates working js file, which is good. But I am not able to use
    browserDevelopmentRun
    anymore:
    Module parse failed: Unexpected character '@' (1:0)
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See <https://webpack.js.org/concepts#loaders>
    > @charset "UTF-8";/*!
    How can I use the loader in
    browserRun
    too?
    b
    8 replies · 2 participants
  • a

    Ayfri

    06/01/2022, 9:57 PM
    Hi, how would I deel with TS code where there is a getter that returns a type but the setter accepts another type ?
    interface IPointData {
            public x: number;
            public y: number;
    }
    
    declare class ObservablePoint<T extends any = any> extends IPointData {}
    
    declare class DisplayObject {
            public get position(): ObservablePoint;
            public set position(pos: IPointData);
    }
    How do I type this in Kotlin ?
    b
    3 replies · 2 participants
  • a

    andylamax

    06/02/2022, 11:45 AM
    Kotlin/JS has been shown no love at all in the newly updated roadmap 😢
    😿 1
    j
    b
    +1
    7 replies · 4 participants
  • j

    Jonathan Ellis

    06/02/2022, 6:32 PM
    Is there a way to have multiple main() methods in a js project, or do I just need to comment out all but one?
    b
    e
    4 replies · 3 participants
  • j

    Jonathan Ellis

    06/02/2022, 7:31 PM
    Am I missing something, or is there no support for creating a new instance via reflection in the js runtime?
    b
    1 reply · 2 participants
  • j

    Jonathan Ellis

    06/02/2022, 7:31 PM
    On the JVM I'd use KClass.primaryConstructor but that doesn't exist on js
    t
    1 reply · 2 participants
  • h

    hfhbd

    06/02/2022, 8:28 PM
    I try to use
    @JsModule("@bootstrap/scss/_buttons.scss") private external val Style: dynamic
    to load the style via web pack, similar what kmdc does, but who does it work as a consumer? My showcase project fails with: bootstrap module not found, because it should not explicit depend on this npm module: https://github.com/hfhbd/bootstrap-compose/pull/195
    b
    23 replies · 2 participants
  • g

    Garth Gilmour

    06/03/2022, 8:08 AM
    I'm porting a Kotlin / React app to the new HTML DSL. Previously I could insert a wastebasket icon into a span like this:
    attrs.unsafe { +"&#128465;" }
    But this is not supported in the new syntax. I have tried:
    dangerouslySetInnerHTML!!.__html = "&#128465;"
    But no luck...
    j
    t
    8 replies · 3 participants
  • g

    Garth Gilmour

    06/03/2022, 12:26 PM
    Related to the above what is the new syntax for links? Previously we had
    a("<http://somewhere>") {}
    but this no longer compiles. Although that's what the documents show. One would expect:
    a {
    href = "<http://somewhere>"
    }
    But this doesn't work either.
    j
    t
    7 replies · 3 participants
  • m

    Moussa

    06/03/2022, 5:39 PM
    Hey guys, Wanted to ask a quick question if someone faced the same issue. I want to have JS target for NodeJS and another one for browser and I want in both to use
    fetch
    instead of
    XMLHttpRequest
    Is there is a documentation for that part in KMM documentation or a workaround that you know of?
    a
    4 replies · 2 participants
  • n

    Norbi

    06/04/2022, 4:49 PM
    When I build my project in Idea (CTRL+F9) the
    jsBrowserProductionWebpack
    task is executed. How can I force the execution of
    jsBrowserDevelopmentWebpack
    instead? Thanks.
    b
    1 reply · 2 participants
  • j

    Jeff Davidson

    06/05/2022, 5:29 AM
    I'm trying to use the same Kotlin/JS code in two environments, one of which has access to the "chrome.scripting" namespace and one in which "chrome.scripting" is undefined. I made an external declaration in a file with
    @file:JsQualifier("chrome.scripting")
    and an
    external fun executeScript(...)
    method, and it works fine when the namespace exists. However, if it's undefined, the generated JS fails to load even if I never actually try calling the method, since the code tries to declare a variable equal to "chrome.scripting.executeScript", which breaks. Is there a way to make such an external declaration where it does not attempt to initialize this variable unless/until the method is actually called?
    r
    2 replies · 2 participants
  • r

    Racka N

    06/05/2022, 7:49 PM
    Hello everyone. So I'm try to get into Kotlin/JS and have tried following the official hands on guide. It seems like the included react-youtube-lite is deprecated and even adding just makes the screen go blank when I try to access the video player. The react-youtube-lite page say we should migrate to @lite-embed/react which i tried to do but that has brought a compilation error regarding webpack 5 no longer adding polyfills:
    Module not found: Error: Can't resolve 'util' in 'C:\Users\bmkil\IdeaProjects\Kotlin-Conf-React\build\js\node_modules\cacheable-lookup\source'
    for a lot of
    Modules
    and
    BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it.
    I tried using this doc to resolve them but have had no luck so far. And resources regarding this are very scarce. Any help would be appreciated
    1 reply · 1 participant
  • r

    Robert Jaros

    06/06/2022, 6:37 PM
    When using Turkish locale (on linux
    LC_ALL=tr_TR
    ) the task names from the kotlin gradle plugin somehow get translated (e.g.
    frontendBrowserProduct�onRun
    or
    frontendBrowserProduct�onWebpack
    ) and builds with some
    tasks.getByName("....")
    calls fail. Anyone have an idea why is this happening?
    e
    2 replies · 2 participants
  • r

    Racka N

    06/07/2022, 9:25 AM
    What's the equivalent of the "%" length unit in Kotlin/JS?
    a
    2 replies · 2 participants
  • o

    Ovsyannikov Alexey

    06/07/2022, 9:59 AM
    Hello everybody. I faced the problem with coroutine contexts in Kotlin JS. It changes the name of getting function and as a result
    CoroutineContext#get
    returns
    is not a function
    error when it is underhood have wrong name (compiled name in my case is
    t.get_9uvjra_k$
    , but called is
    t.get_1pi7hg_k$
    ). Maybe somebody know how to fix it?
    a
    12 replies · 2 participants
  • r

    Racka N

    06/07/2022, 6:20 PM
    A simple Glassmorphism UI sample with Kotlin/JS. Might be helpful for learning how to use kotlin-emotion for CSS and how to style components. There's a scarcity of good resources regarding this and I'm sharing since it may be useful to other Kotlin/JS newbies like me. Github link: https://github.com/racka98/Kotlin-JS-Glass-UI
    👍 3
    t
    3 replies · 2 participants
  • a

    Ayfri

    06/08/2022, 6:27 AM
    What is the effect of this change ?
    t
    2 replies · 2 participants
  • j

    Joost Klitsie

    06/10/2022, 12:53 PM
    Hello my people! I was wondering: Is there a way to improve compilation speed with (with using browserDevelopmentRun -- continuous)? Now it is 30 seconds if I am lucky, 1 minute if I am less lucky. I was wondering: would more modules work? I could split things up in feature modules, this works great for android development. Also, is it common that my app reloads twice when a change is detected? Usually when a change is detected and a build is executed, my app directly reloads (without any changes of course). Then after the build is done, it reloads again (with the changes)
    r
    b
    +1
    3 replies · 4 participants
  • a

    Ayfri

    06/10/2022, 9:11 PM
    Hey, will there be any way soon to see all the sources from the External Librairies menu in the Project files ? For now we can't read any of the
    .knm
    file but if we see declaration of methods in these files it works by looking in the gradle cache, but it would be very useful to be able to see the entire code of libraries directly, like in JVM.
    ➕ 1
    t
    2 replies · 2 participants
  • j

    Jonathan Willis

    06/11/2022, 2:25 AM
    I have a backend project in kotlin that i want to convert to Javascript. Is there an out of the box kotiln to js compiler I can use?
    🤨 3
    n
    n
    12 replies · 3 participants
  • a

    Anders Kielsholm

    06/11/2022, 10:09 PM
    Until recently I've been able to build and run my nodejs application (a server) by copying a single a single file to my sever after running
    productionExecutableCompileSync
    . All of a sudden it however starting failing with a lot of errors when starting the application, e.g.:
    Error: Cannot find module './kotlin-kotlin-stdlib-js-ir.js'
    . As far as I remember I haven't changed anything except for updating to newest Intellij and kotlin plugin. Updating to Kotlin 1.7.0 (from 1.6.21) didn't do any difference either. Anyone else tried the same or similar?
    ✅ 2
    t
    3 replies · 2 participants
  • c

    Cheick Kante

    06/13/2022, 5:43 AM
    I'm using Kotlin-react-wrapper- v18 this line would work on v17, however not anymore on v18. What's the correct way of adding bootstrap attributes to a button
    t
    3 replies · 2 participants
  • m

    MrPowerGamerBR

    06/14/2022, 4:23 AM
    Did anyone have this issue after updating to Kotlin 1.7.0 when trying to use
    jsBrowserProductionRun
    or
    jsBrowserDevelopmentRun
    ? The generated JS does work if I host it in a webserver manually. By looking at this (https://github.com/vaadin/flow/issues/13952), it seems that the
    @webpack-cli/serve
    package should be pinned to 1.6.1, and it seems that because the version is declared as "^1.6.1", it pulls version 1.7.0 to my project (well, at least that's what the yarn.lock file says 😛).
    * What went wrong:
    Execution failed for task ':web:dashboard:frontend:jsBrowserProductionRun'.
    > [webpack-cli] TypeError: cli.isMultipleCompiler is not a function
      [webpack-cli] TypeError: cli.isMultipleCompiler is not a function
          at Command.<anonymous> (C:\Users\Leonardo\Documents\IdeaProjects\LorittaBot\LorittaCinnamon\build\js\node_modules\@webpack-cli\serve\lib\index.js:146:35)
          at async Promise.all (index 1)
          at async Command.<anonymous> (C:\Users\Leonardo\Documents\IdeaProjects\LorittaBot\LorittaCinnamon\build\js\node_modules\webpack-cli\lib\webpack-cli.js:1674:7)
    "@webpack-cli/serve@^1.6.1":
      version "1.7.0"
      resolved "<https://registry.yarnpkg.com/@webpack-cli/serve/-/serve-1.7.0.tgz#e1993689ac42d2b16e9194376cfb6753f6254db1>"
      integrity sha512-oxnCNGj88fL+xzV+dacXs44HcDwf1ovs3AuEzvP7mqXw7fQntqIhQ1BRmynh4qEKQSSSRSWVyXRjmTbZIX9V2Q==
    s
    v
    +1
    7 replies · 4 participants
  • g

    gbaldeck

    06/15/2022, 2:52 PM
    I'm starting a frontend project with Kotlin/JS and the React wrappers and I'm a little confused with how I should be using kotlin-styled-next. I see in the example projects that the FC function is used to make function compents. But it does not seem to support styledDiv. The lower case fc function does support it but it looks like it is considered legacy because it is in the FC.legacy.kt file when I look at the source. What should I be using with kotlin-styled-next?
    t
    m
    8 replies · 3 participants
  • a

    Achifal

    06/16/2022, 12:10 PM
    Hello. I tried to switch to IR compiler and found the following issue
    class IRTest {
        val numberToText = js("{'1' : 'one', '2' : 'two'}")
    
        @Test
        fun test() {
            val key = "1"
            assertEquals(true, js("key in this.numberToText"))
        }
    }
    fails with
    Cannot use 'in' operator to search for '1' in undefined
    while
    class IRTest {
        val numberToText = js("{'1' : 'one', '2' : 'two'}")
    
        @Test
        fun test() {
            val key = "1"
            val numberToTextCopy = this.numberToText
            assertEquals(true, js("key in numberToTextCopy"))
        }
    }
    works as expected. Could anyone explain this behavior? Thanks in advance for your help!
    t
    k
    3 replies · 3 participants
  • t

    Tóth István Zoltán

    06/16/2022, 12:10 PM
    Hm the "How would you feel if you could no longer use Kotlin/JS?" question in the new multiplatform survey sent me on an emotional rollercoaster. I really wonder if there are plans to remove the JS support from multiplatform because lack of interest. That would mean that I better stop working on the JS compiler plugin I started to write because it will become useless in the future and it does not worth the time invested. Also, we have quite some software in production that use Kotlin/JS and it would take a lot of time to migrate to ... I don't know what, back to JavaScript?
    g
    n
    2 replies · 3 participants
  • g

    gbaldeck

    06/16/2022, 3:24 PM
    Is there an up to date sample project I can take a look at that has tests setup to run in the browser? I'm having trouble getting my tests to run by following the official docs.
    t
    7 replies · 2 participants
Powered by Linen
Title
g

gbaldeck

06/16/2022, 3:24 PM
Is there an up to date sample project I can take a look at that has tests setup to run in the browser? I'm having trouble getting my tests to run by following the official docs.
t

turansky

06/18/2022, 5:13 PM
We have tests here
But we use common configuration
g

gbaldeck

06/19/2022, 12:27 AM
I am trying to run the browserTest gradle task to test what is rendering on the screen. An alternative would be to use something like enzyme but not sure if there is a wrapper for that
Here's my
build.gradle.kts
file for the javascript portion of my multi project build. I have a common project and jvm project also.
plugins {
    kotlin("js")
}

group = "com.learner.frontend"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

val kotlinWrappersVersion = "1.0.0-pre.340"

dependencies {
    implementation(project(":shared"))
    implementation(enforcedPlatform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:$kotlinWrappersVersion"))
    implementation("org.jetbrains.kotlin-wrappers:kotlin-react")
    implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom")
    implementation("org.jetbrains.kotlin-wrappers:kotlin-styled-next")
    implementation("org.jetbrains.kotlin-wrappers:kotlin-react-router-dom")
    implementation("org.jetbrains.kotlin-wrappers:kotlin-redux")
    implementation("org.jetbrains.kotlin-wrappers:kotlin-react-redux")

    testImplementation(kotlin("test-js"))
}

kotlin {
    js(IR) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport.enabled = true
            }
            testTask {
                useKarma {
                    useChrome()
                }
            }
        }
    }
}
t

turansky

06/19/2022, 12:11 PM
We use puppeteer with Chrome Headless on CI server here
to test what is rendering on the screen
Looks like puppeteer use case, he will install required Chrome version yourself
View count: 5