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

    Jiri Bruchanov

    11/25/2019, 4:14 PM
    Anyone who could help ? I have an issue with tests, because of missing external dependency... I do have simple hello world app with external js dependency, the code works fine in a browser. But not sure how to tell gradle to include my external js when running my tests.
    r
    t
    i
    • 4
    • 9
  • h

    hellman

    11/26/2019, 7:09 AM
    I created a Kotlin/JS Gradle project with three modules, “main”, “common” and “service-worker”. “main” is the script that my index.html loads. This will in turn install a ServiceWorker from /service-worker.js. How do I configure the main module to pick up the JS output from the module it includes as a dependency?
    t
    • 2
    • 6
  • t

    thana

    11/26/2019, 8:45 AM
    I stumbled across following problem: i get a
    Long
    value from the klock-library. Unfortunately klock-js brings its own kotlin.js library hence the
    Kotlin.Long
    returned by klock is not the same
    Kotlin.Long
    the rest of the application uses. Is there a way to exclude klock's dependency on kotlin?
    r
    i
    • 3
    • 9
  • h

    hellman

    11/26/2019, 6:26 PM
    So I can get two Kotlin/JS module to build and each has its own browserRun and browserWebpack tasks. But even if I add a dependency from one to the other I can’t get the JS files from the dependency to be included. Any suggestions?
    i
    • 2
    • 27
  • j

    Joffrey

    11/27/2019, 2:48 PM
    Is there a reflection-based way (not
    kotlinx.serialization
    ) in Kotlin/JS to parse JSON into Kotlin data classes?
    @Test
        fun jsonTest() {
            data class Person(val name: String)
    
            val expected = Person("Bob")
            val parsedPerson = JSON.parse<Person>("""{"name":"Bob"}""")
    
            assertEquals(expected, parsedPerson)
        }
    This test gives:
    AssertionError: Expected <Person(name=Bob)>, actual <[object Object]>.
    d
    r
    d
    • 4
    • 28
  • f

    Filippo Orru

    11/28/2019, 8:12 AM
    I've used create-react-kotlin-app and now I'd like to include a gradle/maven library. How to go about this? I've managed to track down the .jar file but I'm not sure how to include the jar / call it within kotlin. Please help 😅
    h
    j
    • 3
    • 16
  • f

    Filippo Orru

    11/28/2019, 4:02 PM
    It me again. I'm trying to get the new text value from an input, when the user types. How to do this in Kotlin?
    onClickFunction = {
    println(it.target.value)
    }
    Doesn't work
    a
    • 2
    • 1
  • i

    ian.shaun.thomas

    11/29/2019, 5:27 PM
    Using
    org.jetbrains.kotlin.js
    it's pretty trivial to get the browser dev setup working with the
    kotlin.target.browser {}
    . What's not is where to go from here. How would I package the node outputs in
    /build/js
    to be usable as static inputs in a ktor application in a multi module project? Given the js plugin seems to properly call node under the hood I'm imagining I can call some release task but reading the plugin source I'm not seeing anything obvious and the available tasks seem to be devoid of anything that would appear to create a consolidated output I can use statically.
    ❓ 1
    • 1
    • 1
  • h

    hellman

    11/30/2019, 12:55 PM
    The package in question in
    lit-element
    , and the error I get when loading the JS file in the browser is
    Uncaught ReferenceError: LitElement is not defined
    t
    • 2
    • 2
  • f

    Filippo Orru

    12/02/2019, 8:16 AM
    Hello I'm using react-kotlin but the
    useState(0)
    Hook doesn't work! It throws the following Error:
    Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons (...)
    and then lists the reasons. Why is that? My Code is the following:
    d
    • 2
    • 7
  • j

    Janelle Fullen

    12/02/2019, 10:52 PM
    Hello, I noticed that Kotlin Multiplatform mangles API method names for Kotlin native libraries when transpiling to JS (e.g. ListArray.get is mangled like get_14h3f). Is there way to prevent this mangling? I want to be able to interact with native Kotlin objects from JS.
    t
    a
    +2
    • 5
    • 5
  • j

    Janelle Fullen

    12/03/2019, 8:03 PM
    Can someone help me understand why MutableMaps in Kotlin JS don't have all the methods I expect they'd have? E.g. put().
    t
    z
    t
    • 4
    • 6
  • g

    Gurupad Mamadapur [FH]

    12/04/2019, 8:41 AM
    Hi, can someone please help me with this (ReactJs app with Kotlin)? Can't resolve the
    react
    imports (Unresolved reference for
    import react.dom.*
    )
    import react.dom.*
    import kotlin.browser.document
    
    fun main() {
        render(document.getElementById("root")) {
            h1 {
                +"Hello, React+Kotlin/JS!"
            }
        }
    }
    build.gradle file -
    plugins {
        id 'org.jetbrains.kotlin.js' version '1.3.61'
    }
    
    group 'com.example'
    version '1.0-SNAPSHOT'
    
    repositories {
        mavenCentral()
        jcenter()
        maven { url "<https://dl.bintray.com/kotlin/kotlin-js-wrappers>" }
        maven { url "<https://dl.bintray.com/kotlin/kotlinx>" }
    }
    
    kotlin {
        target {
            browser()
        }
    
        sourceSets {
            main {
                dependencies {
                    implementation kotlin('stdlib-js')
                    implementation kotlin('test-js')
    
                    implementation kotlin('stdlib-js')
                    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.10.0"
                    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.2.0"
    
                    implementation(npm("core-js", "^2.0.0"))
                    implementation(npm("svg-inline-loader", "0.8.0"))
                    implementation(npm("kotlinx-html", "0.6.12"))
                    implementation(npm("@jetbrains/kotlin-react", "16.6.0-pre.67"))
                    implementation(npm("@jetbrains/kotlin-react-dom", "16.6.0-pre.67"))
                    implementation(npm("@jetbrains/kotlin-styled", "1.0.0-pre.67"))
                    implementation(npm("@jetbrains/kotlin-extensions", "1.0.1-pre.67"))
                    implementation(npm("@jetbrains/kotlin-css", "1.0.0-pre.67"))
                    implementation(npm("@jetbrains/kotlin-css-js", "1.0.0-pre.67"))
                    implementation(npm("react", "16.8.3"))
                    implementation(npm("react-dom", "16.8.3"))
                    implementation(npm("inline-style-prefixer", "5.0.4"))
                    implementation(npm("styled-components", "3.4.10"))
                    implementation(npm("@jetbrains/logos", "1.1.4"))
                    implementation(npm("@jetbrains/ring-ui", "2.0.0-beta.11"))
                }
            }
    
            test {
                dependencies {
                    implementation(npm("enzyme", "3.9.0"))
                    implementation(npm("enzyme-adapter-react-16", "1.12.1"))
                }
            }
        }
    }
    i
    c
    • 3
    • 7
  • b

    bashor

    12/05/2019, 12:00 PM
    https://twitter.com/bashorov/status/1202558024537300993
    ❤️ 6
    c
    s
    • 3
    • 2
  • r

    Robert Jaros

    12/05/2019, 12:00 PM
    Nothing about webpack configuration?
    b
    • 2
    • 1
  • r

    Rob Murdock

    12/05/2019, 9:08 PM
    Any setup improvements for the jsTest task in a multiplatform build? I cobbled together my own process near the beginning of 2019 and am hoping things have improved (especially unpacking the js dependency tree to a location that a js test process can access it)
    s
    t
    • 3
    • 14
  • c

    Christian Dräger

    12/05/2019, 10:32 PM
    is there a way to use jest as test runner instead of karma as descriped here https://kotlinlang.org/docs/reference/js-project-setup.html#configuring-test-task? what i’m trying to archive is to have unit tests that don’t start a browser (unlike the karma tests) and testing my react components with enzyme. is an example regarding react with enyme available somewhere? or are their other hints how to archive testing that you are just to when comming from typescript (like react testing with jest and enyme)
    s
    • 2
    • 3
  • n

    Nikky

    12/06/2019, 6:35 PM
    does anyone here have a example app for kotlin-react that uses gradle instead of setup via yarn ? i have no idea how to setup the index.html to display the app
    s
    • 2
    • 1
  • n

    Nikky

    12/06/2019, 8:19 PM
    can i add startscripts from package.json somehow to the npm configuration in the frontend plugin? this example: https://github.com/ScottHuangZL/my-kotlin-app/blob/master/package.json#L16-L22
    s
    • 2
    • 3
  • r

    Rob Murdock

    12/09/2019, 4:16 PM
    I’m having a fun problem this morning - I setup some libraries I publish to use the js test runner, and it appears that in the “build to release” (that no longer uses snapshots), I get errors that look like the following:
    kotlinNpmInstall FAILED
    377
    error Couldn't find package "myproject-package@1.4.5" required by "myproject-package-test@1.4.5" on the "npm" registry.
    😅 Seems like once it has a version number, it tries to install the project I’m currently building from npm. Is this an issue other people have workarounds for? Should I open a ticket somewhere?
    i
    • 2
    • 2
  • s

    spand

    12/10/2019, 9:43 AM
    I noticed the frontend plugin disabled the use of
    package-lock.json
    . Is
    package-lock.json
    supported in the new javascript plugin ?
    i
    • 2
    • 5
  • g

    galex

    12/10/2019, 11:22 AM
    Does someone have a working example of how to release a Multiplatform JS target as a pure NPM module?
    t
    i
    • 3
    • 4
  • b

    Boris Dudelsack

    12/10/2019, 11:39 AM
    Does auto rebuild / auto reload for Kotlin/JS work in 1.3.61 or is it only supposed to work later in 1.4?
    i
    n
    +2
    • 5
    • 20
  • n

    Nikky

    12/10/2019, 4:19 PM
    without the frontend plugin, just using
    kotlin("js")
    how do i add dev dependencies for using webpack plugins and the like ?
    i
    • 2
    • 3
  • j

    James Ward

    12/10/2019, 8:05 PM
    Hi all, I was hoping to consume a Kotlin JS subproject in a Micronaut server subproject as a Jar dependency but it didn't work because it wasn't a JVM artifact. I was able to depend on the Jar directly: https://github.com/GoogleCloudPlatform/air-draw-demo/blob/kotlinconf/server/build.gradle.kts#L27 But that isn't ideal. Any ideas on a better way to do this?
    b
    • 2
    • 1
  • n

    Nikky

    12/10/2019, 9:08 PM
    i am looking for examples/suggestions on which libraries work best with kotlin-react and is multiplatform
    👍 1
    b
    • 2
    • 5
  • g

    galex

    12/11/2019, 9:43 AM
    Hello, in an mpp project the js file is generated as
    umd
    . I see that all classes and object (singletons) are generated as function() so I am not sure how I am supposed to use it in JavaScript, as when called I get
    undefined
    as returned value. Any idea?
    b
    • 2
    • 2
  • e

    ESchouten

    12/11/2019, 10:14 AM
    Is is possible to override/upgrade the dukat version included in the kotlin-gradle-plugin?
    i
    • 2
    • 2
  • m

    marstran

    12/11/2019, 12:31 PM
    Hi, I’m trying to get kotlin-react to work for the first time. I tried building my project with Maven, but I’m getting some “module is not defined” errors when I run it in the browser. After some searching, I think it’s because I need the “core-js” dependency from NPM. Now my problem is, I can’t find any way to include NPM-dependencies through Maven. Do anyone know if you can include those with Maven only (without a package.json and doing “npm install”? It think this is the equivalent in Gradle:
    kotlinFrontend {
        npm {
            dependency "core-js"
        }
    }
    r
    • 2
    • 14
  • r

    Robert Jaros

    12/12/2019, 10:42 AM
    In the old frontend plugin I could do this:
    kotlinFrontend {
        define("PRODUCTION", true)
    }
    How to achieve the same in the new Kotlin/JS plugin?
    i
    • 2
    • 3
Powered by Linen
Title
r

Robert Jaros

12/12/2019, 10:42 AM
In the old frontend plugin I could do this:
kotlinFrontend {
    define("PRODUCTION", true)
}
How to achieve the same in the new Kotlin/JS plugin?
i

Ilya Goncharov [JB]

12/12/2019, 11:25 AM
If you can set production mode for webpack, you can set it in plain js file in
webpack.config.d
folder
config.mode = 'production' // set production mode to webpack
config.devtool = 'source-map' // or even false - it configure source map not to inline into bundle
Since 1.3.70 production and development build will be builtin You can just run necessary task for development or for production
r

Robert Jaros

12/12/2019, 11:30 AM
But can I read this mode inside the
js
file in
webpack.config.d
?
currently I've got:
if (defined.PRODUCTION) {
 // ...
}
View count: 3