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

    sdeleuze

    06/20/2019, 1:58 PM
    https://twitter.com/sdeleuze/status/1141705982512439297
    🔥 5
    t
    s
    n
    • 4
    • 9
  • r

    robstoll

    06/20/2019, 6:44 PM
    I sometimes get
    JavaScript name (foo_cbqzx6$) generated for this declaration clashes with another declaration
    but I cannot really see why it happens for some functions but not for others. Could it be a bug I should report?
    a
    • 2
    • 2
  • u

    U75957

    06/21/2019, 9:45 AM
    If we interact with TS framework, which expect that TS classes is inherited with TS
    extends
    , we get defective inheritance (in short, it does not work). As workaround I do such thing:
    class Kotlin : TypeScript() {
        init {
            tslib.__extends(Kotlin::class.js, TypeScript::class.js)
        }
    }
    Can this be done somehow more elegantly / correctly? I think extending of TS class should be supported by Kotlin/JS. With annotation of external TS class or somehow else.
    u
    a
    • 3
    • 21
  • u

    U75957

    06/21/2019, 11:27 AM
    this::class.supertypes
    is marked as supported for JS in the documentation. But in fact compiler produce error
    Unsupported [This reflection API is not supported yet in JavaScript]
    t
    • 2
    • 1
  • s

    sdeleuze

    06/22/2019, 6:33 AM
    Anybody had a look to https://svelte.dev? I like it, and I am wondering how such approach could be implemented in Kotlin. Compiler plugin?
    :yes: 1
    g
    s
    +2
    • 5
    • 7
  • y

    Yan Pujante

    06/23/2019, 4:43 PM
    According to the KotlinJsDcePlugin.kt source code:
    project.afterEvaluate {
                val outputDir = project.buildDir
                    .resolve(DEFAULT_OUT_DIR)
                    .resolve(kotlinCompilation.target.disambiguationClassifier?.let { "$it/" }.orEmpty() + kotlinCompilation.name)
    
                val configuration = project.configurations.getByName(kotlinCompilation.compileDependencyConfigurationName)
    
                with(dceTask) {
                    classpath = configuration
                    destinationDir = dceTask.dceOptions.outputDirectory?.let { File(it) } ?: outputDir
                    source(kotlinTask.outputFile)
                }
            }
    the
    destinationDir
    variable is not available until
    afterEvaluate
    . Is there a specific reason? In my build file I have this:
    task assembleWeb(type: Sync) {
      configurations.compile.each { File file ->
        from(zipTree(file.absolutePath), {
          includeEmptyDirs = false
          include { fileTreeElement ->
            def path = fileTreeElement.path
            path.endsWith(".js") && (path.startsWith("META-INF/resources/") ||
                !path.startsWith("META-INF/"))
          }
        })
      }
        from compileKotlin2Js.destinationDir
        // from runDceKotlinJs.destinationDir
      into webDir.child("dynamic").child("js")
      
      dependsOn classes
    }
    and
    compileKotlin2Js.destinationDir
    is available... but if I uncomment
    runDceKotlinJs.destinationDir
    it is
    null
    unless I wrap the entire thing in
    afterEvaluate{}
    . That doesn't seem right...
    r
    • 2
    • 2
  • i

    Ilya Goncharov [JB]

    06/24/2019, 3:29 PM
    Is there any way to use kotlin resources in webpack bundle in Kotlin/JS 1.3.40? Now there is error
    ERROR in ....
      Module not found: Error: Can't resolve 'foo/bar.svg' in ...
    r
    s
    g
    • 4
    • 10
  • v

    victoralissont5

    06/25/2019, 11:14 PM
    Moreover, Kotlin's concept of suspending function provides a safer and less error-prone abstraction for asynchronous operations than futures and PROMISES. Could someone explain why this is true?
    g
    • 2
    • 2
  • e

    Eduard Minasyan

    06/26/2019, 8:13 PM
    Hello everyone. I've been playing around with kotlin in browser and faced such a thing, that kotlin-js does not provide exception stacktrace. It seems a little bit strange and uncomfortable, but I guess it is because there is no standardized stacktrace feature in javascript. Haven't I missed something? May be anyone can hint some library that expose stacktrace as an extension? I didn't found any. 😞
    r
    s
    • 3
    • 9
  • u

    U75957

    06/27/2019, 11:12 AM
    Such code
    js("{'Content-Type':'application/json'}")
    Produce:
    {Content-Type: 'application/json'}
    Content-Type
    without quotes is not valid js code. Produce error
    Unexpected token
    Is it compiler bug or I miss something?
    r
    • 2
    • 2
  • a

    ankushg

    06/27/2019, 7:49 PM
    Hey friends, I've been writing some Kotlin/JS code and had some questions about how to handle JS blobs in a nicer way. I noticed that if I have a method that takes in
    data class Foo(val bar: Int)
    as a parameter, I can call it from JS and pass in the blob
    {"bar": 1}
    and it will Just Work. Is this officially supported, or is it just an unreliable side-effect of how Kotlin/JS internally represents data classes? Does this work with nested classes (e.g.,
    data class Foo2(val myBar: Bar)
    and
    data class Bar(...)
    )? If I had a class that was declared as
    data class Foo3(val bar: SomeEnumClass)
    , is there a simple way to allow me to call it from JS using a blob with an
    Int
    map it to
    SomeEnumClass
    in Kotlin? Maybe something like an alternate constructor or property with a backing fields?
    r
    • 2
    • 6
  • i

    Ilya Goncharov [JB]

    06/29/2019, 9:11 AM
    It seems that source mapping doesn't work properly for now, isn't it? Is it known problem? It seems, that it can be fixed, using
    compileKotlinJs {
        kotlinOptions {
            sourceMapEmbedSources = "always"
        }
    }
    But I think, it should be more elegant
    d
    r
    +2
    • 5
    • 13
  • a

    altavir

    06/30/2019, 11:11 AM
    I've got a noob question. I have an Element and I want to attach another element (threejs canvas) to it using element size for the canvas. Then I need to resize canvas when parent element is resized. Simple
    element.clientWidth
    works with bootstrap columns, but if I have some kind of inner structure,
    element.clientWidth
    returns zero. As far as I can understand it happens because when I take the measurement, the element is not yet rendered. What is the best way to treat this problem?
    r
    • 2
    • 3
  • t

    turansky

    06/30/2019, 2:29 PM
    SVGAnimateElement isn’t declared in Kotlin/JS stdlib. Is there any roadmap for such cases? https://developer.mozilla.org/en-US/docs/Web/API/SVGAnimateElement
    b
    • 2
    • 4
  • m

    Mark

    06/30/2019, 6:48 PM
    Hi, I've been trying to stand up some tests in a project using the new browserTest task for the Koltin/JS 1.3.40 plugin and seem to be having inconsistent results with it finding test sources. Is there anything I can do to point it at the specific source set? Right now, the task runs fine but it finds nothing inside of the test source. Thanks!
    b
    • 2
    • 5
  • g

    galex

    07/01/2019, 11:26 AM
    Hello, do the new
    org.jetbrains.kotlin.js
    gradle plugin has capabilities to deploy the code as an npm module? Where can I find its documentation?
    a
    s
    • 3
    • 14
  • f

    Fudge

    07/01/2019, 12:37 PM
    What is the way to (manually) test a Kotlin/Multiplatform library's Javascript side in an HTML page? Essentially have a frontend sub-project in which I can use the library in.
    b
    • 2
    • 2
  • t

    Tristan Caron

    07/01/2019, 7:53 PM
    Hello, I was wondering, is there someone working a on framework for building webapps using kotlin without having to use HTML? It’s just out of curiosity. WebAssembly will (not only) bring the possibility to use alternatives to JavaScript. Maybe something similar can be thought about HTML + CSS. Flutter allow to target the web. Basically, they are rendering in a canvas. (I don’t know what will be the solutions proposed for accessibility, text editing and so on). Some people from the Swift community did something from SwiftUI (just a toy though) https://github.com/SwiftWebUI/SwiftWebUI, creating actual HTML. And recently another typescript framework has been released, with an API close to what we can find on mobile (https://typescene.dev) also creating HTML.
    r
    b
    • 3
    • 2
  • f

    Fudge

    07/02/2019, 2:36 PM
    How can I access an
    object
    from Javascript`? Kotlin:
    package foo.bar
    
    object Obj {
        fun func() = 2
    }
    JS:
    var x = foo.bar.Obj.func() // Invalid!
    s
    • 2
    • 5
  • t

    Tristan Caron

    07/04/2019, 12:23 AM
    Hello, I wanted to try the now Kotlin/JS, especially the npm support. I create a new project in Intellij (Gradle, with Kotlin DSL, and Kotlin/Js/Browser). Running it works just fine. But I have a message when I want to edit
    build.gradle.kts
    ,
    There were some errors during scripts dependencies resolution, some resolution might be missing
    . When I try to use the function
    npm
    it says it’s unresolved:
    implementation(npm("lib", "0.0.0"))
    I am using Kotlin 1.3.41
    s
    j
    • 3
    • 13
  • r

    Ryan Batchelder

    07/05/2019, 3:37 PM
    Is there an annotation/configuration that will cause Gradle to output compiled kotlin/js to a different “package”? I have a multiplatform lib that I’m building which compiles to JVM and JS, and I was hoping to not have to use the fully qualified package name to call shared code from JS-land.
    h
    • 2
    • 7
  • j

    Joffrey

    07/08/2019, 4:26 PM
    Hi guys, is there a way to incrementally migrate a TS code base to Kotlin/JS? A bit of context. I have a Gradle multi-project build which consists of: - a Spring Boot server (in Kotlin) - a React app (in typescript) built using Create React App and the Gradle node plugin on top of it I have recently extracted the API client code from the TS subproject into a Kotlin common (multiplatform) subproject of its own. Now, I'd like to setup a Gradle build for the React app that can depend on the local multiplatform subproject, and that can compile the existing TS files. Is this possible? In the end, the goal is to migrate little by little the whole React app to Kotlin.
    u
    s
    • 3
    • 5
  • t

    Tuan Kiet

    07/09/2019, 1:56 AM
    How to properly call
    suspend
    function from
    js
    site? or are we shouldn’t call at all?
    g
    j
    s
    • 4
    • 6
  • c

    Casey Brooks

    07/10/2019, 9:45 PM
    This might just be me not knowing much about Webpack, but how can I call my Kotlin/JS browser code from a Webpack bundle generated with the 1.3.40 multiplatform lib? I’ve got my multiplatform lib set up, run
    jsBrowserWebpack
    to create the bundle, and added it to my HTML page with a
    <script>
    tag, but i can’t figure out how to access my module from there
    u
    • 2
    • 4
  • a

    aakira

    07/11/2019, 2:03 AM
    Hi, Do you know a website created using Kotlin/JS?
    u
    u
    c
    • 4
    • 9
  • a

    aakira

    07/11/2019, 12:13 PM
    And I have another question. Can we hide a
    kotlin.js
    file on website created using Kotlin/JS ? I download the kotlin.js file when I open this website(https://turanukimaru.github.io/FEHSIM/). So, I can’t find the website created by Kotlin/JS if we can hide a kotlin.js file. I saw it by network tab in chrome developer tools.
    r
    g
    +2
    • 5
    • 30
  • x

    xlj44400

    07/13/2019, 3:03 AM
    how can I use kotlin-stdlib-js dev or local SNAPSHOT by gradle kts I try this , but it can not work
    kotlin-stdlib-js_dev.js
    g
    • 2
    • 3
  • o

    o.semen

    07/15/2019, 9:19 AM
    message has been deleted
    a
    • 2
    • 1
  • u

    U75957

    07/16/2019, 2:16 PM
    Such code:
    external interface A {
        fun foo(p1: Any)
    }
    
    fun main() {
        A::foo.name
    }
    produce such js code:
    getCallableRef('foo', function ($receiver, p1) {
          return $receiver.foo(p1), Unit;
        }).callableName;
    It looks like a lot of excess. I expect just
    'foo'
    .
    p
    a
    • 3
    • 3
  • b

    BearDev

    07/18/2019, 10:06 PM
    Hey im trying to find why an unmodified brand new project made in IntelliJ from Kotlin -> JS Client and JVM server | Gradle fails to build with
    C:\Users\User\IdeaProjects\TestMulti2\build\js\packages\TestMulti2\node_modules\.bin\webpack:2
    basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
              ^^^^^^^
    
    SyntaxError: missing ) after argument list
        at new Script (vm.js:80:7)
        at createScript (vm.js:274:10)
        at Object.runInThisContext (vm.js:326:10)
        at Module._compile (internal/modules/cjs/loader.js:664:28)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
        at Module.load (internal/modules/cjs/loader.js:600:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
        at Function.Module._load (internal/modules/cjs/loader.js:531:3)
        at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
        at startup (internal/bootstrap/node.js:283:19)
    
    FAILURE: Build failed with an exception.
    Like I said, this is a project created fresh from the template with 0 modifications made. Thanks in advance.
    s
    • 2
    • 3
Powered by Linen
Title
b

BearDev

07/18/2019, 10:06 PM
Hey im trying to find why an unmodified brand new project made in IntelliJ from Kotlin -> JS Client and JVM server | Gradle fails to build with
C:\Users\User\IdeaProjects\TestMulti2\build\js\packages\TestMulti2\node_modules\.bin\webpack:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
          ^^^^^^^

SyntaxError: missing ) after argument list
    at new Script (vm.js:80:7)
    at createScript (vm.js:274:10)
    at Object.runInThisContext (vm.js:326:10)
    at Module._compile (internal/modules/cjs/loader.js:664:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)

FAILURE: Build failed with an exception.
Like I said, this is a project created fresh from the template with 0 modifications made. Thanks in advance.
s

snrostov

07/19/2019, 4:18 AM
Hi! Looks like you're on Windows. Windows is not supported at 1.3.40. Will be supported at 1.3.50. The first EAP will be published in a couple of days.
1.3.50 eap published: https://discuss.kotlinlang.org/t/kotlin-1-3-50-early-access-preview/13525
👍 2
b

BearDev

07/19/2019, 12:23 PM
Thank you. Can confirm the issue is resolved with 1.3.50-eap.
View count: 3