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

    janvladimirmostert

    02/14/2021, 5:17 PM
    How would I go from a suspending function to a Promise or just getting rid of the suspend completely? (on the JVM, you would use runBlocking for example) My submit function is using Coroutines, but I want to JsExport the functions making use of the submit function
    class POST(
    	val uri: String,
    	val json: String,
    ) {
    
    	suspend fun <T> submit(): T {
    		return window.fetch(
    			input = "${ENV.server}$uri",
    			init = RequestInit(
    				body = json,
    				method = "POST",
    				headers = json("content-type" to "application/json; charset=UTF-8"),
    			)
    		).await().json().await().unsafeCast<T>()
    	}
    
    }
    @JsExport
    @ExperimentalJsExport
    object Data {
    	suspend fun getColumns(request: ColumnRequestVO): ColumnResponseVO {
    		return POST(uri = "/columns", json = request.toString()).submit<ColumnResponseVO>()
    	}
    }
    Declaration of such kind (suspend function) cant be exported to JS
    v
    t
    a
    • 4
    • 5
  • j

    Jackson Bean

    02/16/2021, 12:09 AM
    I know it's very new and experimental, but has anyone had success with porting a well-known npm package such as "express" into kotlin declarations using dukat?
    r
    • 2
    • 1
  • m

    Marc Knaup

    02/18/2021, 5:19 PM
    Is there any way to force some code to be run non-lazily when the JS file is loaded? Even when using
    -Xir-property-lazy-initialization
    . With
    -Xir-per-module
    I need to know if a certain module was already loaded. The only which comes to mind is to set a global variable when loading that module, and check if that variable set from other modules.
    s
    • 2
    • 3
  • b

    Big Chungus

    02/18/2021, 5:54 PM
    What KotlinJS-first declarative ui frameworks are out there (if any)?
    n
    • 2
    • 2
  • j

    jvmusin

    02/18/2021, 6:41 PM
    Hi all! I'm trying to add
    react-tooltip
    to my project. https://www.npmjs.com/package/react-tooltip It has some static methods like
    ReactTooltip.show(element)
    How can I add these methods with the new IR compiler? I used a workaround to avoid problems with
    default
    described here: https://github.com/anton-bannykh/web-app-react-kotlin-js-gradle/blob/IR-fixes/src/main/kotlin/ReactPlayer.kt This thread is related: https://github.com/JetBrains/kotlin-wrappers/issues/361 And this is my code for ReactTooltip:
    import react.RClass
    import react.RProps
    
    @JsModule("react-tooltip")
    @JsNonModule
    external object ReactTooltip {
        val default: RClass<ReactTooltipProps>
    }
    
    external interface ReactTooltipProps : RProps {
        var id: String
        var type: String
    }
    I tried to add this method as an instance method on
    object ReactTooltip
    , but JS says it's not a function. I also tried to add it like
    val show: (target: Element) -> Any = definedExternally
    , but it doesn't seem to work too. Any suggestions?
    t
    • 2
    • 10
  • e

    Etienne

    02/18/2021, 10:15 PM
    I get that I'm in a single-thread environment, and it's probably the cause.. from my playing around the behaviour I'm seeing is that "if a suspend function itself calls a suspend function, it's just going to block." But if that's true, then doesn't it just mean
    Flow.single()
    is broken in kotlin-js? Makes me think I'm probably not understanding correctly what's going on.
    a
    • 2
    • 15
  • s

    spand

    02/23/2021, 9:05 AM
    Js interop question. How do I get a reference to a kotlin class constructor that javascript can call
    new
    on ?
    class KotlinClass extends ExternalClass {
        constructor(p1 : Context) : super(p1) {
        }
    }
    When I pass
    KotlinClass::class.js
    it will pass the
    KotlinClass
    in javascript land.. but the
    super
    call is placed in the
    function KotlinClass_init()
    which seems to ever only be called from Kotlin. I tried getting a reference to
    KotlinClass_init
    but doing
    ::KotlinClass
    in kotlin land doesnt work either. I think its because it is wrapped in a function leading to a loss of the
    this
    value. Ultimately I cannot see how javascript can ever new a Kotlin class that needs to pass parameters to its super constructor. It seems to me that it is a compiler flaw that the kotlin constructor body is not placed in the native javascript constructor instead of this init function.
    s
    • 2
    • 3
  • y

    your_rubicon

    02/25/2021, 5:17 AM
    message has been deleted
    o
    • 2
    • 1
  • s

    Sebastian Aigner

    02/25/2021, 1:38 PM
    📛 Hi folks! We’re continuing our quest to increase adoption of the new Kotlin/JS IR compiler – and we want to make it more visible which projects already support or use Kotlin/JS IR. So, a small request: - If you have a published project that you compile with the Kotlin/JS IR compiler, or - If you are maintaining a library that publishes artifacts compatible with JS IR …we’d love if you would add our “Kotlin/JS | IR supported” badge to your README, to let others know that you are already embracing the future of Kotlin/JS 🛸! It’s as easy as adding the following snippet to your markdown:
    [![Kotlin JS IR supported](<https://img.shields.io/badge/Kotlin%2FJS-IR%20supported-yellow)](https://kotl.in/jsirsupported)>
    👍 6
    :kotlin-intensifies: 13
    r
    r
    a
    • 4
    • 5
  • j

    Jurriaan Mous

    02/25/2021, 3:11 PM
    I try to use a Kotlin/JS IR based module inside a TypeScript project. And it seems the module after assembling misses a
    "types": "kotlin/shared.d.ts"
    field in the
    package.json
    . Without that field TypeScript did not detect the types of the module in the project. I for now added the field manually with:
    compilations["main"].packageJson {
        customField("types", "kotlin/shared.d.ts")
    }
    Did I miss a setting or should I report an issue to YouTrack?
    b
    • 2
    • 1
  • h

    Harald Pehl

    02/26/2021, 2:54 PM
    In case anyone is interested, I gave a talk on Kotlin/JS. The topic includes how to get started, JS interop, the Kotlin/JS ecosystem, React, and fritz2. The slides and code samples are available at https://github.com/hpehl/kotlinjs-talk/.
    :kotlin-intensifies: 1
    👏 4
    :kotlin-flag: 1
    🤘 1
    n
    • 2
    • 2
  • g

    gaetan

    02/28/2021, 6:36 PM
    Does anybody knows how to keep the
    Kotlin.defineModule
    js function when using DCE?
    t
    • 2
    • 3
  • a

    Animesh Sahu

    03/01/2021, 3:54 PM
    Is there something like
    @JvmSynthetic
    in K/JS?
    t
    • 2
    • 28
  • b

    Big Chungus

    03/03/2021, 10:34 AM
    Just raised an issue on kotlin yt to making npm publishing functionality natively available via kotlin js and multiplatform plugins. Vote if that's something that'd be of use to you.
    ➕ 1
    😮 4
    s
    • 2
    • 2
  • s

    steamstreet

    03/08/2021, 7:14 PM
    Am I correct that intra-project dependencies are not working correctly with the IR compiler? I have a project with 2 modules, and one depends on the other. But when I try to build, I get a
    "Couldn't find package "…-jsIr@1.0.1" required by "…-jsLegacy@1.0.1 on the "npm" registry."
    even though I have them both configured with
    js(BOTH) {}
    b
    r
    • 3
    • 10
  • c

    Christoph Hock

    03/08/2021, 7:53 PM
    Is there a better way to get the target of a event as a HTMLElement?
    val iframeDocument = element.contentWindow?.document
    iframeDocument?.body?.addEventListener("mouseup", callback = { event ->
        val target = event.target?.unsafeCast<HTMLElement>()!!
    })
    r
    t
    • 3
    • 5
  • a

    andrea.santurbano

    03/09/2021, 9:57 AM
    Hi everybody I’m trying to create a multiplatform library with no external deps, in particular I need to cover these two platforms: • JVM => in order to reuse it in Scala/Java/Kotlin projects • Javascript => in order to use in Cloud Functions (Azure/AWS/Google Cloud) The output of the compilation works perfectly for the JVM target but struggling with the output of Javascript Compilation (I’m using
    IR
    ). The produced code seems not do depend to Kotlin as it contains internally all the required data structures and they’re not compatible with the Kotlin.js library Can somebody help me or point to some useful resource that explain how to use kotlin-to-js compiled code into pure js applications?
    b
    • 2
    • 33
  • s

    Sebastian Aigner

    03/09/2021, 2:24 PM
    Cross-posting this here, since y’all are the main target audience anyway 😉
    :kotlin-intensifies: 3
    👍 4
    🚂 1
    🆒 3
    a
    o
    • 3
    • 2
  • d

    Dmitry Romanov [JB]

    03/11/2021, 8:42 AM
    Hey folks! We see in our analytics that some of you aren’t using Gradle in their Kotlin/JS projects. I would like to chat and learn a bit more about such projects. Please DM me or let me know about you in the :thread-please:
    :gradle: 7
    c
    • 2
    • 2
  • a

    Ashish Kumar Joy

    03/11/2021, 2:08 PM
    Hi all, Is there any specific configuration required to run js test when we use IR backend. Before using IR backend for js target my js test were running but after switching to IR non of the js test are running. Here is my build gradle file: https://github.com/ashishkujoy/kotlin-js-jvm-library/blob/main/build.gradle.kts
    a
    r
    o
    • 4
    • 12
  • s

    Shabinder Singh

    03/12/2021, 11:58 AM
    Hey All I am building a JsonObject like following , I want to
    put(key="data",*ArrayBuffer)*
    but put only accepts JsonElement , so how to do this? as JS Function expects an ArrayBuffer there... Any Help is Appreciated!
    m
    • 2
    • 13
  • s

    Shabinder Singh

    03/12/2021, 5:06 PM
    Hey All I have Been Struggling Fo Creating An External Class for using this : https://github.com/egoroof/browser-id3-writer library in my Kotlin/JS Project But i cant get to create an object of this class as it expects new keyword. Any Help is Appreciated as I couldnt get it to work even after few hours of trying... whenever I try to Instantiate ID3Writer , at runtime it crashes giving error:
    ID3Writer is not a constructor
    t
    r
    • 3
    • 15
  • c

    crummy

    03/13/2021, 9:43 AM
    @JsExport seems really handy - however it's a shame I can't export
    Map<X, Y>
    . I can't export
    List
    or
    Collection
    either but those I can map to
    Array
    - is there an equivalent solution for `Map`s?
    d
    t
    • 3
    • 3
  • c

    crummy

    03/13/2021, 9:16 PM
    Is there a common way to automatically modify the exported .d.ts file generated by @JsExport? In particular I'd like to strip
    kotllin.js
    from
    kotlin.js.promise
    (see KT-43632) and I guess I can hack up some Gradle to do this but wondered if there was a convention or tool for this.
    t
    • 2
    • 6
  • d

    Derek Ellis

    03/14/2021, 2:43 AM
    I'm getting this error now even though I haven't changed any project configuration. Not entirely sure why or where it's coming from. Would anyone here know?
    Execution failed for task ':common:jsBrowserDevelopmentWebpack'.
    > Module 'fs' not found
    r
    • 2
    • 4
  • d

    Derek Ellis

    03/15/2021, 3:18 AM
    So, using sqldelight's js driver with the IR compiler everything compiles fine but at runtime an Uncaught ReferenceError is throw because it can't find a
    SqlJs
    object which I believe is supposed to be bundled by webpack from the
    sql.js
    package. I've tried a handful of different custom webpack config changes but nothing seems to help.
    t
    • 2
    • 9
  • p

    Peter Ertl

    03/17/2021, 3:19 PM
    when building a naked “hello world” in kotlin/js is getting a 500k webpack bundle in build/distributions/{myproject}.js the lowest I can get or is there an option like “treeshaking”, “optimize”, etc. I am missing?
    🇳🇴 1
    😵 1
    j
    t
    +5
    • 8
    • 193
  • w

    willyrs

    03/17/2021, 8:40 PM
    hey guys, it's a super stupid question, but.. How do I add an image in react/kotlin? I've added a png in the jsMain/resources folder but it can't be found at runtime, and it's not present in the build/js bundle
    ✔️ 1
    t
    • 2
    • 13
  • i

    iseki

    03/18/2021, 6:11 AM
    Is dukat ready for production environment? Looks there're many problems on the output definitions. And... I don't know how to resolve them manually.
    🇳🇴 1
    😞 1
    t
    i
    v
    • 4
    • 8
  • р

    Ролан

    03/18/2021, 6:32 AM
    Is there a nice way to load WASM into kotlin-js, or the only way is to pass by JavaScript? Example links and any kind of advice on this will be highly appreciated. Huge thanks
    b
    • 2
    • 8
Powered by Linen
Title
р

Ролан

03/18/2021, 6:32 AM
Is there a nice way to load WASM into kotlin-js, or the only way is to pass by JavaScript? Example links and any kind of advice on this will be highly appreciated. Huge thanks
b

Big Chungus

03/18/2021, 8:33 AM
Declare WASM browser API via kotlin external declarations and use them directly
👍 1
р

Ролан

03/18/2021, 9:29 AM
And how would one go about passing callbacks written in kotlin-js? https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#interacting-with-code-call-function-pointers-from-c
b

Big Chungus

03/18/2021, 9:50 AM
again, declare them as externals and pass those
👍 1
I'm assuming you;re not using Kotlin/WASM, but if you do, you can find a lot of js interop examples here
р

Ролан

03/18/2021, 9:56 AM
Thank you, this is very helpful. I am new to this, and indeed I will have a look at Kotlin/WASM as well
b

Big Chungus

03/18/2021, 10:29 AM
Don't use kotlin wasm. Its lvvm version is abandoned
р

Ролан

03/18/2021, 10:51 AM
Ok thank you
I am using emcc
View count: 11