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

    taso

    02/02/2018, 12:54 PM
    Hello, we have such setup for a
    react
    project with KotlinJs. https://github.com/novoda/spikes/blob/master/game-of-life-multiplatform/web/build.gradle The below gradle script is something we copy pasted. When I upgrade to Kotlin version
    1.2.21
    , the task mentioned in the very bottom
    copyDependenciesKotlinJs
    is gone. Since I don’t understand the setup, I’m really not sure how to fix it.
    task copyStatic(type: Copy) {
    from "$rootDir/src/web"
    into "$buildDir/web"
    }
    
    task buildBundle(type: NpmTask, dependsOn: [npmInstall, runDceKotlinJs]) {
    args = ["run", "dist"]
    }
    
    task copyKotlinJs(type: Copy, dependsOn: compileKotlin2Js) {
    def workDir = "$buildDir/classes/main/"
    from(workDir) {
    include "*.js"
    include "*.js.map"
    }
    into "$workDir/dependencies"
    }
    
    task devBuild(dependsOn: [npmInstall, copyStatic, copyKotlinJs])
    
    assemble.dependsOn buildBundle, copyStatic
    
    afterEvaluate {
    copyKotlinJs.dependsOn copyDependenciesKotlinJs
    }
    t
    a
    • 3
    • 14
  • t

    taso

    02/02/2018, 12:54 PM
    Can someone point me to an up to date
    kotlin2js
    example with the latest kotlin version and with
    react
    ,
    react-dom
    and
    kotlinx-html-js
    ?
    t
    t
    f
    • 4
    • 5
  • t

    Tristan Caron

    02/02/2018, 7:44 PM
    Is it possible to use kotlinx.coroutine with create-react-kotlin-app?
    b
    a
    • 3
    • 2
  • s

    sabag.ronen

    02/03/2018, 6:21 AM
    how to show alert with kotlin js ?, I have expected that it will be easy as with console.log
    l
    g
    • 3
    • 5
  • s

    sabag.ronen

    02/03/2018, 11:08 AM
    there is a “kotlin way” for CSS?
    c
    • 2
    • 2
  • b

    benleggiero

    02/05/2018, 1:39 AM
    Is there an easier way to debug Kotlin/JS? Currently I just use Chrome’s Dev Tools
    b
    • 2
    • 2
  • g

    gaetan

    02/05/2018, 2:39 PM
    Is it a bug ?
    interface GeoJson{
        val type:String
        val coordinates:Array<*>
        
        fun asPoint() = Point(coordinates as Array<Double>)
    }
    data class Point(val coordinates:Array<Double>)   
    
    fun main(args: Array<String>) {        
        val json = """{"type":"Point", "coordinates":[1.0, 2.0]}"""  
        val obj = JSON.parse<GeoJson>(json).asPoint()        
        println("${obj.coordinates}")
    }
    https://try.kotlinlang.org/#/UserProjects/2fobglofrrpnr9b0pru299uu31/6d1saqhqrbndev90djqurmuiv0
    b
    t
    b
    • 4
    • 16
  • c

    chadmorrow

    02/06/2018, 5:08 PM
    get a lot of these errors
    Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Invalid referrer policy
    g
    • 2
    • 7
  • m

    marcinmoskala

    02/07/2018, 5:38 AM
    What does it mean that we enable/disable sourceMaps in
    kotlin-frontend-plugin
    ? https://github.com/Kotlin/kotlin-frontend-plugin
    g
    • 2
    • 3
  • s

    spand

    02/07/2018, 9:16 AM
    I am trying to define a kotlin external class for a javascript class. But how do I access its static members (the properties defined on the javascript constructor function)
    b
    f
    • 3
    • 3
  • f

    Filipp Riabchun

    02/07/2018, 9:22 AM
    One possible way to do it is this:
    external class Foo {
      // instance members
    }
    
    JsName("Foo")
    external object FooConstructor {
      // static members
    }
    s
    • 2
    • 1
  • s

    spand

    02/07/2018, 10:36 AM
    Any good practices for typing option objects?
    f
    • 2
    • 2
  • f

    Francis

    02/07/2018, 3:39 PM
    I'm trying to get started with kotlin/react. But just the first step for running the sample project fails hard. Using create-react-kotlin-app, it can't even load. I got
    Kotlin.defineModule is not a function
    . In the console :`Object.kt:20 Uncaught TypeError: Kotlin.defineModule is not a function`
    a
    • 2
    • 1
  • f

    Filipp Riabchun

    02/07/2018, 3:46 PM
    Usually it's cured by
    rm -rf node_modules/.cache
    . Unfortunately we haven't found a permanent fix at the moment
    f
    • 2
    • 3
  • m

    mmaillot

    02/07/2018, 3:50 PM
    I try to use kotlin-js to get data from external webservice. I try with this code :
    val request = XMLHttpRequest()
    request.open("GET", endpoint, false)
    request.send(null)
    if (request.status.toInt() == 200) {
      return JSON.parse(request.responseText)
    }
    And I get this error :
    XMLHttpRequest is not defined
    . My code run on NodeJS and NodeJS doesn't have XMLHttpRequest... Should I use another lib and wrap it ?
    b
    t
    • 3
    • 5
  • s

    spierce7

    02/07/2018, 5:58 PM
    I'm trying to attach an intellij ultimate debugger to Chrome to debug kotlin code running in browser. I'm getting an error:
    Use jsonreader.setlenient(true) to accept malformed json at line 1 column 1 path $
    . Should I be using the "Attach to Node.js/Chrome" configuration, or is there a better way? I can see my kotlin sources and everything in the browser, just trying to get it to work in the IDE as well.
    b
    • 2
    • 2
  • g

    gaetan

    02/07/2018, 11:31 PM
    @albertgao This is how I debug tests: My tests are done with karma -> mocha -> qunit. When I need to do some debugging, I use this karma configuraton:
    module.exports = function(config) {
        config.set({
            frameworks: ['qunit', 'browserify'],
            reporters: ['mocha'],
            files: [
                'build/classes/kotlin/main/*.js',
                'build/classes/kotlin/test/*.js',
                'build/node_modules/*.js',
                {pattern: 'build/classes/kotlin/test/*.json', watched: true, served: true, included: false}
            ],      
            colors: true,
            logLevel: config.LOG_INFO,
            browsers: [
                // 'ChromeHeadless',
                // 'PhantomJS',
                'Chrome'
            ],
            // singleRun: true,
            singleRun: false,
            autoWatch: false,
            captureTimeout: 5000,
    
            // singleRun: false, // Karma captures browsers, runs the tests and exits
    
            preprocessors: {
                '**/*.js': ['browserify']
            }
        })
    };
    Using Chrome instead of PhantomJS or ChromeHeadless with
    singleRun: false
    will launch chrome with the debug interface. You can then launch the test and use the chrome dev tools.
    a
    • 2
    • 2
  • g

    gaetan

    02/07/2018, 11:33 PM
    The other option for kotlin js test code that runs without the browser api, is to launch the test with only mocha+qunit. You can then create a mocha run configuration inside intellij and do some debug from intellij.
    a
    • 2
    • 2
  • s

    spierce7

    02/07/2018, 11:42 PM
    I'm trying to use coroutines in JS, but I'm getting an error:
    Cannot find module "kotlinx-coroutines-core-js"
    . How should I be packaging the coroutine library (or any library written in kotlin for that matter)? My instinct was to check npm, but didn't find anything. If I use the DCE plugin, it outputs all the JS files in one place which is nice, but how do I get the non-minified js files for kotlin-js libraries I'm using? Right now, the only thing I can think of is to check out the github.
    a
    • 2
    • 2
  • a

    alexcouch

    02/08/2018, 8:25 AM
    I don't know what I'm doing with it. I'm reading the documentation but when trying to write code I'm blinded. I tried to mark a dir as a source but it asked for a Kotlin/JVM configuration. And I know that when using something like Angular requires the tool ts2ks but I'm using AngularJS so not sure how that's working out. Unless the way that writing kotlin/js code in intellij is different than write kotlin/jvm (tools-wise)
    s
    b
    • 3
    • 11
  • s

    spand

    02/08/2018, 9:38 AM
    Say I have this javascript
    new $.Zebra_Tooltips(elm, {});
    Is the only way to call new to have a class constructor in Kotlinjs ?
    b
    • 2
    • 2
  • l

    lewik

    02/08/2018, 12:50 PM
    Like js "delete"
    t
    a
    • 3
    • 13
  • k

    karelpeeters

    02/08/2018, 12:59 PM
    Make it a
    var
    and set it to
    null
    ?
    t
    f
    • 3
    • 2
  • t

    Tristan Caron

    02/08/2018, 1:07 PM
    I would have say some thing like
    js("'undefined'")
    s
    • 2
    • 1
  • a

    araqnid

    02/08/2018, 5:32 PM
    just call
    require
    (i.e. clearly for side-effect) rather than assigning it to a val?
    t
    • 2
    • 1
  • g

    gbaldeck

    02/08/2018, 9:18 PM
    I've been seeing a lot of talk about web assembly lately. I'm sure you guys get this all the time but is it currently on the radar as compile target for Kotlin?
    o
    • 2
    • 1
  • g

    gaetan

    02/09/2018, 10:47 AM
    After the callback hell there is the js testing frameworks hell: how to find the correct configuration that works. testing coroutines works with mocha but not qunit. testing browser code needs karma. testing multi-module code needs a testing framework compatible with requirejs or commonjs or to pack modules before tests. packing modules is long karma + commonjs is fast but not working on windows. karma + browserify + qunit is slower but works also on windows (but doesn’t work with coroutines). #jsfatigue 😪
    z
    f
    • 3
    • 8
  • f

    Femi Sotonwa

    02/09/2018, 12:23 PM
    Does anyone have a solution to compiling multiple .kt files into separate independent .js files, instead of the default where multiple .kt files are compiled into one single .js file?
    g
    t
    m
    • 4
    • 4
  • c

    czyzby

    02/10/2018, 12:24 PM
    Did anyone have problems with
    src/main/kotlin
    not being marked as source folder in IntelliJ when using Gradle?
    plugins {
        id("kotlin2js")
    }
    
    dependencies {
        compile(kotlin("stdlib-js"))
    }
    g
    • 2
    • 4
  • c

    czyzby

    02/10/2018, 3:06 PM
    Interesting project!
Powered by Linen
Title
c

czyzby

02/10/2018, 3:06 PM
Interesting project!
View count: 2