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

    Andrew Reed

    04/29/2021, 4:39 PM
    Is there a way to conditionally include NPM dependancies depending on the type, e.g. Browser or Node. I have a scenarios where i do not wish to include the npm dependancies on my node target, but need them for my browser target.
    b
    r
    +2
    • 5
    • 24
  • a

    andylamax

    05/02/2021, 8:11 AM
    is there a way i can configure my
    JS(IR)
    target to have its main configuration target
    browser
    while it's test configuration target
    node
    ? I need to be able to write my integration tests with
    javascript
    and I am too tired to creating a whole new
    jvm
    target just for the purpose of
    testing
    a web app. Suggestions?
    r
    • 2
    • 2
  • w

    WukongRework.exe

    05/02/2021, 9:37 PM
    hey guys i have a few questions about how kotlin JS handles npm dependencies so for context: i am helping a friend set up a project in the kotlin JS target and we have run into a few issues, namely they require a library called mathjs, primarily for LU Decomposition (with or without partial pivoting) now, according to the docs, adding
    @JsModule("mathjs")
    and
    @JsNonModule
    was the best way to solve npm packages on the kotlin side (according to the docs https://kotlinlang.org/docs/using-packages-from-npm.html) however this didnt work and to quote my friend: "i had literally no idea if the npm install worked like there was just no feedback on it because no gradle errors but like there wasn't any positive confirmation so while everything wasn't working i wasn't even sure if the dependency worked" and "just what the sample tells me to do but it straight up didnt work and the only error was "lusolve is not a function" like it just was completely useless and there' s no error on compilation either it's just a runtime error" they ended up finding out a solution to fix the problem (linked in the pictures below) and it was an abstract external class marked with
    @JsModule
    and a companion object storing all of the needed functions i have two questions: i understand that kotlin JS is a relatively new target and doesnt get as much love as JVM or even native from wat ive seen, but y is documentation so poor on this? (is this something that should be brought up in #docs-revamped or is it already a known problem?) i also understand that the JS / npm / node ecosystem is very large and was wondering if these "hacks" will be the norm of doing things moving forward or if there are plans to make them better side note: sorry for the language in these pictures, it was late at night and they had spent a lot of time trying to figure this out
    r
    • 2
    • 3
  • t

    Tarun Chawla

    05/04/2021, 3:38 PM
    Am writing image carousel for first time on web. Am thinking about creating a layout of this kind:
    <Prev Button/a> <Image> <Next Button/a>
    Am using Bulma css framework to design things. Do you have any suggestions which I should take care while implementing it?
    :not-kotlin: 2
    😛lacard: 1
    • 1
    • 2
  • e

    Ethan Davidson

    05/05/2021, 3:04 AM
    Is anyone maintaining https://github.com/Kotlin/kotlinx-browser ? @Alexey Trilis [JB] is the only person who ever committed there, and there are two PRs (one of them several months old).
    a
    s
    • 3
    • 5
  • t

    Tarun Chawla

    05/05/2021, 12:13 PM
    can someone confirm what this group is for? Apparently the question I asked is non conformant for this group.
    k
    r
    • 3
    • 4
  • b

    bsimmons

    05/05/2021, 2:41 PM
    Is there an easy way to access test resources while running tests in kotlin JS?
    d
    • 2
    • 4
  • h

    hikamaeng

    05/06/2021, 2:40 AM
    how to convert intellj module to dynamic import js module and use other module? bundle size so big..T.T
    t
    • 2
    • 5
  • w

    willyrs

    05/06/2021, 5:59 AM
    Whats the best way to produce a js (or better TS) library to be used in a react project? Right now I'm building for browser and then copy the generated .js to my react project and if feels like an hack
    b
    • 2
    • 3
  • r

    Rescribet

    05/06/2021, 1:09 PM
    Is there any way to enable export of documentation comments on the generated
    .d.ts
    files for the JS IR output?
    s
    • 2
    • 3
  • t

    Tarun Chawla

    05/07/2021, 9:07 AM
    I guess this is the right forum for this question. I have builded a webpage by following this: https://play.kotlinlang.org/hands-on/Building%20Web%20Applications%20with%20React%20and%20Kotlin%20JS/01_Introduction But am getting this error in browser console:
    Uncaught 
    Object { "message_8yp7un$_0": undefined, "cause_th0jdv$_0": null, stack: "i/</e.captureStack@http://localhost:9000/static/output.js:3:209256\n$n@http://localhost:9000/static/output.js:3:54266\ngn@http://localhost:9000/static/output.js:3:54329\nbn@http://localhost:9000/static/output.js:3:54433\nPn@http://localhost:9000/static/output.js:3:55118\ni/</e.throwNPE@http://localhost:9000/static/output.js:3:213780\ni/t.ensureNotNull@http://localhost:9000/static/output.js:3:15312\ni/le.prototype.addRestaurantPage/<@http://localhost:9000/static/output.js:30:8941\nC@http://localhost:9000/static/output.js:10:610418\nH.render_2955dm$@http://localhost:9000/static/output.js:10:911384\ni/le.prototype.addRestaurantPage@http://localhost:9000/static/output.js:30:8899\nve@http://localhost:9000/static/output.js:30:9565\ni@http://localhost:9000/static/output.js:30:134260\n@http://localhost:9000/static/output.js:30:134271\nn@http://localhost:9000/static/output.js:1:340\n@http://localhost:9000/static/output.js:30:1183\nn@http://localhost:9000/static/output.js:1:340\n@http://localhost:9000/static/output.js:1:1139\n@http://localhost:9000/static/output.js:1:1150\n@http://localhost:9000/static/output.js:1:203\n@http://localhost:9000/static/output.js:1:207\n", name: "NullPointerException" }
    
    "cause_th0jdv$_0": null
    
    "message_8yp7un$_0": undefined
    
    name: "NullPointerException"
    
    stack: "i/</e.captureStack@http://localhost:9000/static/output.js:3:209256\n$n@http://localhost:9000/static/output.js:3:54266\ngn@http://localhost:9000/static/output.js:3:54329\nbn@http://localhost:9000/static/output.js:3:54433\nPn@http://localhost:9000/static/output.js:3:55118\ni/</e.throwNPE@http://localhost:9000/static/output.js:3:213780\ni/t.ensureNotNull@http://localhost:9000/static/output.js:3:15312\ni/le.prototype.addRestaurantPage/<@http://localhost:9000/static/output.js:30:8941\nC@http://localhost:9000/static/output.js:10:610418\nH.render_2955dm$@http://localhost:9000/static/output.js:10:911384\ni/le.prototype.addRestaurantPage@http://localhost:9000/static/output.js:30:8899\nve@http://localhost:9000/static/output.js:30:9565\ni@http://localhost:9000/static/output.js:30:134260\n@http://localhost:9000/static/output.js:30:134271\nn@http://localhost:9000/static/output.js:1:340\n@http://localhost:9000/static/output.js:30:1183\nn@http://localhost:9000/static/output.js:1:340\n@http://localhost:9000/static/output.js:1:1139\n@http://localhost:9000/static/output.js:1:1150\n@http://localhost:9000/static/output.js:1:203\n@http://localhost:9000/static/output.js:1:207\n"
    
    <prototype>: Object { constructor: Pn(t), stack: "" }
    How to map this error to the Kotlin code? Earlier if I used to caught these errors, I was able to fix it on spot somehow relating it to kotlin code am writing. But not now because I have written lots of code and suddenly this error is coming in browser console am clueless on how to debug this. can you please point me to the right direction?
    a
    • 2
    • 4
  • j

    Jaroslav

    05/07/2021, 10:54 AM
    Hi, I'd like to share kotlin module between Java and Kotlin/JS modules, some constants and data classes. Is it use case for multi platform building or is there some easier way?
    h
    a
    • 3
    • 5
  • j

    Joost Klitsie

    05/07/2021, 1:06 PM
    Is it/will it be possible to have
    external value class Whatever(whatever: String)
    ?
    a
    • 2
    • 18
  • a

    Animesh Sahu

    05/07/2021, 1:42 PM
    If you use lambdas, you need to return
    Unit.INSTANCE
    from Java side, whereas if you like to use SAM interface you cannot export it to js 😂. Any suggestion to make both part happy?
    t
    • 2
    • 13
  • m

    Martin Feldsztejn

    05/07/2021, 10:51 PM
    Is there a way to get the output JS file of a kotlin/js project to run with node?
    e
    a
    • 3
    • 9
  • m

    Martin Feldsztejn

    05/08/2021, 5:48 AM
    So… I started playing with Kotlin/Js a few weeks ago and most of the projects I found where either a bit outdated or not necessary what I was looking for. I wanted a Kotlin project that could compile into a nodejs server you can later upload into any hosting you’d like and most the examples I found were for “browser”. Therefore, in case someone is interested in taking a look or wants to use it as a guide for your projects, here’s the repo I’ve been uploading the work to. All comments are welcome. https://github.com/martofeld/KotlinNodeJsTest Note: The code itself is very (extremely) basic and its in the app module. Most of my time was invested into fighting with the dukat generated files, configurations, and a few other issues non-code related. It is my intention to keep adding code into the project & publishing the libraries I created into mavenCentral in case they can be useful since I couldn’t find anything similar.
    🙌 1
    a
    j
    +3
    • 6
    • 8
  • y

    yunxing

    05/09/2021, 1:48 PM
    Gradle / intellij generate a large number of tasks for js target -- is there a way to inspect / edit those tasks to know what they each do?
    t
    • 2
    • 3
  • a

    andrewreitz

    05/09/2021, 3:37 PM
    If I have a file in
    test/resources
    how do I load that file in a test? I’m trying
    fetch("./myfile")
    and it is returning a not found error.
    t
    • 2
    • 7
  • a

    Ayfri

    05/09/2021, 11:14 PM
    Hi, how would I type in Kotlin an enum in TS like this :
    export enum UPDATE_PRIORITY {
        INTERACTION = 50,
        HIGH = 25,
        NORMAL = 0,
        LOW = -25,
        UTILITY = -50,
    }
    And a function that have a parameter of this :
    function test(priority: UPDATE_PRIORITY = UPDATE_PRIORITY.HIGH): void
    ?
    t
    • 2
    • 52
  • y

    yunxing

    05/10/2021, 3:02 PM
    when I write
    js("require('fs')").readFileSync
    in kotlin, is there a way to tell what the return type is? The only document I can find is on nodejs, where it says a buffer is returned. However I don't know how to access that in kotlin
    r
    • 2
    • 1
  • r

    Robert Jaros

    05/10/2021, 4:27 PM
    message has been deleted
    🚀 2
    :kotlin-intensifies: 2
    🎉 2
    t
    • 2
    • 3
  • j

    Jonathan Smith

    05/10/2021, 7:06 PM
    I tried with both Safari an Chrome .. both seem to have the same issue.
    s
    • 2
    • 15
  • s

    steamstreet

    05/10/2021, 8:25 PM
    I know there have been some discussions about Kotlin + NodeJS for AWS Lambda, but does anyone have a current example project? Like a hello world? I have a few issues: • how do package, including the Kotlin standard library, etc. • how to exclude some packages, like the AWS package that is provided • how to configure the entry point correctly And before you ask, the reason for doing this is cold-start time. The JVM is killer, and I have some smallish lambdas that I'd like to use but would prefer to use one language throughout my project.
    j
    b
    m
    • 4
    • 11
  • t

    Tomasz Krakowiak

    05/11/2021, 9:17 PM
    Does anyone knows, how advanced DCE is? If I would for example write something like that:
    const val DEBUG = false
    
    fun doSomething(debug : Boolean) {
        if(debug) {
            doSomeDebugStuff()
        }
    }
    Would DCE get rid of
    doSomeDebugStuff
    from output js? Would it work across libraries? Would it work if I would store debug as field of some class?
    t
    • 2
    • 2
  • a

    Andrey Ivanov

    05/12/2021, 12:54 PM
    Hello everybody! I just started trying to develop in kotlin / js and came across a small amount of information on pitfalls (at least in comparison with js). For example, I never found a good explanation of how React.lazy works. Can anyone suggest where to get an example of using lazy / rLazy? I have already despaired in search, there is a function but there is no documentation, or I am blind.
    t
    • 2
    • 6
  • j

    jmfayard

    05/12/2021, 7:34 PM
    Hello, I want to write a multiplatform function
    expect fun executeExternalCommand(args: List<String>, options): String
    On the JVM, I can use
    ProcessBuilder(),
    On Native, I use
    popen
    , but how do I do that on Node/JS?
    • 1
    • 1
  • j

    jmfayard

    05/12/2021, 7:35 PM
    Hello again, my project, supposed to run on Node.JS, depends on ktor-client which is only available with the IR backend and CliKt which is only available with the legacy backend Is there any hope?
    e
    • 2
    • 4
  • r

    rnett

    05/12/2021, 10:26 PM
    Is there any kind of timeline for supporting
    KClass.qualifiedName
    ? It's proving to be quite a pain for some RPC things. I'm not aware of a youtrack issue for it.
    e
    • 2
    • 2
  • a

    Arjan van Wieringen

    05/13/2021, 5:53 AM
    I am looking at https://kotlinlang.org/docs/js-to-kotlin-interop.html and I am a bit confused. I am using IR compiler in my own project and without setting any module I can already get my
    @JSExport
    -ed functions and classes from the module. Is this significantly different in IR compared to the stable Kotlin/JS?
    a
    • 2
    • 1
  • p

    Pepijn de Vos

    05/13/2021, 3:40 PM
    How would I express the following JS array in Kotlin?
    [
              {
                x: [1, 2, 3],
                y: [2, 6, 3],
                type: 'scatter',
                mode: 'lines+markers',
                marker: {color: 'red'},
              },
              {type: 'bar', x: [1, 2, 3], y: [2, 5, 3]},
            ]
    a
    • 2
    • 1
Powered by Linen
Title
p

Pepijn de Vos

05/13/2021, 3:40 PM
How would I express the following JS array in Kotlin?
[
          {
            x: [1, 2, 3],
            y: [2, 6, 3],
            type: 'scatter',
            mode: 'lines+markers',
            marker: {color: 'red'},
          },
          {type: 'bar', x: [1, 2, 3], y: [2, 5, 3]},
        ]
a

andylamax

05/13/2021, 4:33 PM
val arr = arrayOf(
  jsObject {
    x = arrayOf(1,2,3)
    y = arrayOf(2,6,3)
    type = "scatter"
    mode = "lines+markees"
    marker = jsObject {
      color = "red"
    }
  },
  jsObject {
    type = "bar"
    x = arrayOf(1,2,3)
    y = arrayOf(2,5,3)
  }
)
👍 1
View count: 3