https://kotlinlang.org logo
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
  • y

    Yakeen Sewsanker

    07/06/2022, 1:15 AM
    Another Kotlin/JS question, regarding how best to orchestrate gradle to build the
    productionLibrary
    for publishing? I have attempted to do the following:
    tasks.getByName("publishJsNpmPublicationToNpmjs") {
                dependsOn(tasks.getByName("jsBrowserProductionLibraryDistribution"))
                doLast {
    val jsDir = buildDir.resolve("productionLibrary")
    ...
    }
    But
    jsBrowserProductionLibraryDistribution
    does not create
    productionLibrary
    . Any clues to what does?
    b
    • 2
    • 5
  • s

    Sebastian

    07/06/2022, 9:21 AM
    Hey peeps! After upgrading Kotlin from 1.6.10 to 1.6.21 recently, our exported TypeScript definitions are broken for some cases. It’s mostly about Kotlin generating nested comments inside method signatures, e.g.
    /* kotlin.collections.List<any/* com.company.manager.data.ApiAnswer */> */
    ). The inner comment closing statement (
    */
    ) will make the outer comment closing appear as regular code and thus generate a syntax error in TypeScript. I’ll put a slightly more complete example in the thread. Did anyone have any issues like that, or is there any related entry in the issue tracker? I haven’t found anything so far, but can’t imagine that I’m the only one with totally broken TypeScript definitions. 🤔
    • 1
    • 3
  • f

    Florent Martin

    07/07/2022, 12:06 PM
    Has anybody experience with plotly.kt on frontend side? I am working on a multiplatform app and am trying to add the plotly.kt dependencies to the frontend (react/js). I am not able to use this example here: https://github.com/mipt-npm/plotly.kt/blob/master/examples/js-demo/build.gradle.kts, I think “implementation(project(“:plotlykt-core”))” is wrong for me. My Setup is also with Kotlin 1.7 which might be a problem too.
    a
    • 2
    • 22
  • e

    Edoardo Luppi

    07/08/2022, 10:03 PM
    Strange question. Anyone ever tried building a VSCode extension using Kotlin.js?
    b
    • 2
    • 2
  • n

    Nick

    07/09/2022, 5:20 AM
    Doodle 0.8.0 Released 3D Transforms Views can now have full 3D transformations via their
    transform
    property. This works because
    AffineTransform
    has been updated to support scale, rotation, and translations that involve x, y and z axes. The result is that Views can now be placed in a full 3D space by simply giving them a transform that has been modified accordingly.
    import io.nacular.doodle.drawing.AffineTransform.Companion.Identity
    import io.nacular.measured.units.Angle.Companion.degrees
    
    // Rotate this View around they y-axis (through its center) by 45°
    view.transform *= Identity.rotateY(around = view.center, by = 45 * degrees)
    Views can also now render in 3D, since
    Canvas
    also supports the new 3D transforms.
    view {
        render = {
            transform(Identity.rotateY(by = 45 * degrees)) {
                // ...
            }
        }
    }
    3D Perspective A realistic 3D space requires more than just affine transforms (which keep parallel lines parallel). Simulating this requires perspective transforms. Views now have a
    camera
    property, which gives them a perspective when combined with a 3D transform. The following allows the y-axis rotation to look more realistic.
    import io.nacular.doodle.drawing.AffineTransform.Companion.Identity
    import io.nacular.measured.units.Angle.Companion.degrees
    
    // Rotate this View around they y-axis (through its center) by 45°
    view.transform *= Identity.rotateY(around = view.center, by = 45 * degrees)
    
    // Position the View's camera to apply some realistic perspective warping
    view.camera = Camera(position = view.center, distance = 1000.0)
    Canvas also takes a
    Camera
    in its
    transform
    method to enable perspective.
    view {
        render = {
            transform(Identity.rotateY(by = 45 * degrees), camera = Camera(Origin, distance = 1000.0)) {
                // ...
            }
        }
    }
    Kotlin 1.7 Support Doodle now supports 1.7.10!! https://github.com/nacular/doodle/releases/tag/v0.8.0
    :nice: 1
  • b

    Bernhard

    07/11/2022, 12:15 PM
    so regarding tooling: I've got massive tooling pains dealing with module definitions, ts, webpack and ts-jest; will this go away when I go with Kotlin? Or will it be worse since it's another tool on top of webpack
  • a

    andylamax

    07/11/2022, 12:19 PM
    My js tests tasks are failing with no insights at all, all I am getting is
    Cause: command '/home/andylamax/.gradle/nodejs/node-v16.13.0-linux-x64/bin/node' exited with errors (exit code: 1)
    Is there a way to at least get the logs of node to see what went wrong? Also, this is after I upgraded to 1.7.0. Anyone met this problem? how did you solve it?
    r
    • 2
    • 1
  • e

    eygraber

    07/13/2022, 7:18 PM
    Is there a workaround for exporting things nested under an interface other than making the interface a class - https://youtrack.jetbrains.com/issue/KT-52800
  • e

    eygraber

    07/14/2022, 2:39 AM
    I have a multiplatform library (only common code) and I'm targeting Android and iOS. My web team is now asking to target js as well, so they can use the library in their regular javascript codebase. I added the target like this:
    js(IR) {
          if(jsModuleName != null) {
            moduleName = jsModuleName
          }
    
          useCommonJs()
    
          browser {
            webpackTask {
              output.libraryTarget = "commonjs2"
            }
    
            if(isJsLeafModule) {
              binaries.executable()
            }
          }
    }
    What do I do now in terms of getting a javascript file that I can share with my web team?
    a
    s
    • 3
    • 5
  • e

    eygraber

    07/14/2022, 3:37 PM
    Is there any way to strip the package from anything exported with
    JsExport
    ?
    b
    • 2
    • 7
  • e

    eygraber

    07/15/2022, 9:31 PM
    Anyone know if this is considered a bug, or working as intended? https://youtrack.jetbrains.com/issue/KT-52800
  • s

    Slackbot

    07/16/2022, 12:43 PM
    This message was deleted.
    d
    • 2
    • 1
  • s

    Shumaf Lovpache

    07/19/2022, 5:04 PM
    Hi everyone! I'm planning to work on improving experience with web workers in Kotlin JS. So, it is very important for me to know the opinion of the community. Please, share your problems, wishes and thoughts regarding the following topics: • web workers generally • coroutines in Kotlin JS • concurrency in JavaScript (your experience with libraries, use cases etc.) For more information about this feature you can read design notes: https://github.com/Kotlin/KEEP/blob/master/notes/web-workers.md
    👀 4
    :thank-you: 4
    t
    • 2
    • 5
  • c

    Cameron Probert

    07/20/2022, 1:37 AM
    Hi all, I’m having an issue with setting environment variables in
    build.gradle.kts
    to pass as arguments to
    webpack-cli
    . This is working fine in webpack 4, but I’m trying to upgrade to webpack 5. The following works for webpack 4:
  • c

    Cameron Probert

    07/20/2022, 1:38 AM
    Hi all, I’m having an issue with setting environment variables in
    build.gradle.kts
    to pass as arguments to
    webpack-cli
    . This is working fine in webpack 4, but I’m trying to upgrade to webpack 5. The following works for webpack 4:
    kotlin {
        js {
            browser {
                commonWebpackConfig {
                    cssSupport.enabled = true
                    mode = buildMode
                    // stop default export of config object in Webpack code because we do it in 02.envConfig.js webpack extension
                    export = false
                }
    
                // from <https://discuss.kotlinlang.org/t/kotlin-js-react-accessing-configuring-environment-variables/16906/9>
                val envTargetWebpackArgs = listOf("--env.envTarget=$envTarget", "--env.version=$version")
                webpackTask { args.plusAssign(envTargetWebpackArgs) }
                runTask { args.plusAssign(envTargetWebpackArgs) }
            }
    
            // Necessary to fix a compilation issue (see <https://github.com/Kotlin/dukat/issues/106>)
            useCommonJs()
        }
    
        // Force explicit APIs
        explicitApi()
    }
    With the key lines being:
  • a

    Andrey Tabakov

    07/20/2022, 2:10 PM
    Hi, I have a question about suspend function in JS Is there a way to sync asynchronous code in Kotlin/JS? In koltin/JVM we can use
    runBlocking
    Something like this (not working of course)
    fun notSuspendedFunction(block: suspend () -> T): String {
       
      val result = await block() // or runBlocking { block() }
     
      return result
    }
    I'm okay with something like this (not working of course):
    fun notSuspendedFunction(block: suspend () -> T): String {
      val job = GlobalScope.async { block() }
    
      while(job.isCompleted) { /* may be set timeout or something with delay */ }
    
      return job.getCompleted()
    }
    👍 1
    🇳🇴 5
    s
    • 2
    • 1
  • l

    leandro

    07/20/2022, 3:28 PM
    Kotlin 1.7.x compiler seems to duplicate a path if I configure
    moduleName
    in my modules inside
    JS(IR) {}
    .
    js(IR) {
        moduleName = "@myCompany/${project.name}"
        nodejs()
        useCommonJs()
        binaries.executable()
        ...
    }
    Executing
    :assemble
    , the task
    :myModule:compileProductionExecutableKotlinJs
    crashes with:
    /Users/repo/myModule/build/compileSync/main/productionExecutable/kotlin/@myCompany/@myCompany/moduleName.js (No such file or directory)
    Note duplicated “/@myCompany/@myCompany/“. This wasn’t the case with Kotlin 1.6.21 and earlier versions.
    • 1
    • 1
  • j

    Jonathan Ellis

    07/21/2022, 2:18 PM
    Is there an easy fix for this? I'm just using the [multiplatform] build.gradle.kts that intellij generated for me, my level of gradle sophistication is "copy and paste from stackoverflow"
    Execution optimizations have been disabled for task ':jsBrowserProductionRun' to ensure correctness due to the following reasons:
    - Gradle detected a problem with the following location: 'E:\Projects\sketches-js\build\js\packages\sketches-js\kotlin\sketches-js.js'. Reason: Task ':jsBrowserProductionRun' uses this output of task ':jsProductionExecutableCompileSync' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
    e
    • 2
    • 1
  • j

    Jonathan Ellis

    07/21/2022, 2:25 PM
    relatedly, is there a list of what the different js gradle targets do? i couldn't find one in the docs, and I have not been able to guess from the names, e.g. I would not expect jsProductionRun to generate something that shows a big black overlay listing the compiler warnings
    b
    • 2
    • 1
  • a

    andylamax

    07/21/2022, 8:44 PM
    how does one diagnose errors that only say?
    Execution failed for task ':jsNodeTest'.
    > command '/media/andylamax/Auxilliary/Devspace/.gradle/nodejs/node-v16.13.0-linux-x64/bin/node' exited with errors (exit code: 1)
    v
    b
    d
    • 4
    • 9
  • c

    Cameron Probert

    07/22/2022, 1:50 AM
    Hi all. I’m trying to upgrade from webpack 4 to webpack 5 and I’m having an issue with setting environment variables in build.gradle.kts to pass as arguments to webpack-cli. The following works for webpack 4:
    kotlin {
        js {
            browser {
                commonWebpackConfig {
                    cssSupport.enabled = true
                    mode = buildMode
                    export = false
                }
    
                // from <https://discuss.kotlinlang.org/t/kotlin-js-react-accessing-configuring-environment-variables/16906/9>
                val envTargetWebpackArgs = listOf("--env.envTarget=$envTarget", "--env.version=$version")
                webpackTask { args.plusAssign(envTargetWebpackArgs) }
                runTask { args.plusAssign(envTargetWebpackArgs) }
            }
    
            useCommonJs()
        }
    
        explicitApi()
    }
    With the key lines being:
    val envTargetWebpackArgs = listOf("--env.envTarget=$envTarget", "--env.version=$version")
    webpackTask { args.plusAssign(envTargetWebpackArgs) }
    runTask { args.plusAssign(envTargetWebpackArgs) }
    The new way of passing env variables in webpack-cli v4 (which is what webpack 5 uses as far as I understand) is to have a space instead of a
    .
    (i.e.
    --env envTarget=$envTarget
    instead of
    --env.envTarget=$envTarget
    ) Neither the old way nor new way seem to work. The
    webpack.config.js
    file is not generated in the build directory. Both old and new env arg options error in
    :browserProductionWebpack
    with
    Starting process 'command '/Users/cameron/.gradle/nodejs/node-v16.13.0-darwin-x64/bin/node''. Working directory: /Users/cameron/IdeaProjects/app/build/js/packages/app Command: /Users/cameron/.gradle/nodejs/node-v16.13.0-darwin-x64/bin/node /Users/cameron/IdeaProjects/app/build/js/node_modules/webpack/bin/webpack.js --env.envTarget=DEV --env.version=2.3.7 --config /Users/cameron/IdeaProjects/app/build/js/packages/app/webpack.config.js
    Successfully started process 'command '/Users/cameron/.gradle/nodejs/node-v16.13.0-darwin-x64/bin/node''
    [webpack-cli] Error: Unknown option '--env.envTarget=DEV'
    [webpack-cli] Run 'webpack --help' to see available commands and options
    But, when I go to the above working directory and execute that command it runs without failing and the
    webpack.config.js
    file is generated.
    s
    • 2
    • 2
  • a

    Ashley Arthur

    07/22/2022, 12:44 PM
    Hi all. I've been playing with exporting interfaces to JS/TS with KMP version (1.7.10)
    external interface SomeAPI_JS {
        fun doSomeAction(context: Json?)
    }
    It seems like kotlin.js.json comes across as
    Json
    ... but the type is undefine? Is this expected behaviour?
  • a

    Andrey Tabakov

    07/26/2022, 8:17 AM
    How to use yarn 3 berry with yarn plugin instead of use yarn 1 classic?
    b
    • 2
    • 1
  • f

    Franco

    07/27/2022, 12:41 AM
    Hey everyone, I'm having issues running KJS unit tests from the commend line, I am getting the following error:
    Execution failed for task ':browserTest'.
    > Errors occurred during launch of browser for testing.
      - ChromeHeadless
      Please make sure that you have installed browsers.
      Or change it via
      browser {
          testTask {
              useKarma {
                  useFirefox()
                  useChrome()
                  useSafari()
              }
          }
      }
    However I have Chrome installed in my machine so not sure why this is happening. I have tried using Firefox (which I also have installed) and same error occurs. Anyone knows how to fix this?
    a
    • 2
    • 5
  • c

    Cameron Probert

    07/27/2022, 8:03 AM
    Hi everyone. I’m trying to understand what the actual differences in behaviour are between the gradle tasks:
    build
    ,
    browserDevelopmentWebpack
    and
    browserProductionWebpack
    , and also how they differ from setting the webpack mode to
    PRODUCTION
    or
    DEVELOPMENT
    in
    build.gradle.kts
    . I ask this because I was using
    browserDevelopmentWebpack
    but with
    mode=PRODUCTION
    , which seem like they would conflict with each other, and the resulting bundle appeared to be a development bundle (not minified, not DCE’d).
    a
    b
    c
    • 4
    • 7
  • a

    andylamax

    07/27/2022, 2:38 PM
    Hello fellas, Has anyone seen this? Task
    kotlinNpmInstall
    is failing on CI (github actions), but it passes locally. Full error log in thread.
    • 1
    • 1
  • c

    Cheick Kante

    07/29/2022, 12:49 AM
    HI I'm using MUI in trying to change the background-color for the Paper component in Dialog through PaperProps but my app crahes when I do
    Dialog { 
     PaperComponent = FC { //this : ChildrenBuilder it: PaperProps
        <http://it.sx|it.sx> {
            fontSize = FontSize.small
            backgroundColor = Color("transparent")
        }
    
     }
    }
    I have also tried this but doesn't do anything
    Dialog { 
     PaperComponent = FC { //this : ChildrenBuilder it: PaperProps
            it.asDynamic()["background-color"] = "transparent"
            it.asDynamic()["font-size"] = "small"
      }
    }
    Does anyone
    t
    • 2
    • 2
  • l

    Lukas S

    08/01/2022, 8:48 AM
    Hi, I'm trying to create a full stack website with Kotlin/JS and Kotlin/JVM. I would like to create 1 js file for each page that I have on my website, however when building the project it merges all of the files into one js script. I was wondering if there was any way I could change that? I know that if you create submodules, it will compile 1 js file for each module, however I don't feel like this is a good solution as I would have to create one module for each page Thanks
    b
    t
    a
    • 4
    • 9
  • u

    Uğur

    08/02/2022, 2:45 PM
    Hi everyone I am looking for build a full stack web application. I couldn't find an explanatory article. Can you share the articles you know with me?
    r
    • 2
    • 1
  • m

    martmists

    08/02/2022, 3:57 PM
    Is there a way to compile kotlin sources and use the generated class at runtime?
    r
    • 2
    • 4
Powered by Linen
Title
m

martmists

08/02/2022, 3:57 PM
Is there a way to compile kotlin sources and use the generated class at runtime?
r

Robert Jaros

08/02/2022, 4:03 PM
On JS?
You could probably try https://github.com/AlexanderPrendota/kotlin-compiler-server
m

martmists

08/02/2022, 5:08 PM
hm, I guess I'll have to look into sending data from and to a file created with kotlin scripting then. Would you know if that's possible?
Ideally I can avoid having to send user-generated code to the backend of my website and run it in their browser instead ^^
View count: 4