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

    Robert Jaros

    12/12/2019, 11:37 AM
    And another question: currently I have:
    config.plugins.push(new webpack.ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "window.jQuery": "jquery"
    }));
    in
    webpack.config.d/jquery.js
    . With new Kotlin/JS plugin it fails with an error:
    webpack.config.js:69
    config.plugins.push(new webpack.ProvidePlugin({
                            ^
    ReferenceError: webpack is not defined
    i
    • 2
    • 1
  • r

    Robert Jaros

    12/12/2019, 2:05 PM
    When running the project in dev mode, kotlin files from `src/main/kotlin' are compiled into
    build/js/packages/[name]/kotlin/[name].js
    but resources from
    src/main/resources
    are put into
    build/processedResources/Js/main/
    . When I try to
    require
    something from my code, webpack is unable to find these resources. Can it be configured somehow?
    b
    • 2
    • 23
  • g

    galex

    12/12/2019, 2:17 PM
    Is there a way to tell Kotlin/JS to keep all function names instead of adding a
    @JsName
    on each function?
    👍 1
    s
    b
    a
    • 4
    • 4
  • r

    Robert Jaros

    12/12/2019, 6:58 PM
    Why are all the
    *.js
    files from
    webpack.config.d
    inlined into generated
    karma.conf.js
    when running
    build
    or
    test
    task? These files are for
    webpack.config.js
    and karma config is completely different .
    i
    • 2
    • 1
  • r

    Robert Jaros

    12/12/2019, 7:01 PM
    And why I've got this errors when running tests?
    > Task :browserTest
    12 12 2019 19:59:43.293:ERROR [preprocess]: Can not load "webpack", it is not registered!
    
      Perhaps you are missing some plugin?
    
    12 12 2019 19:59:43.296:ERROR [preprocess]: Can not load "sourcemap", it is not registered!
    i
    • 2
    • 10
  • r

    Robert Jaros

    12/12/2019, 7:02 PM
    Anyone knows a project with working tests?
    t
    • 2
    • 1
  • r

    Robert Jaros

    12/13/2019, 12:10 PM
    How to make webpack use js files processed by DCE when generating final bundle?
    t
    • 2
    • 6
  • r

    Robert Jaros

    12/13/2019, 1:57 PM
    is something similar available or planned in the new plugin?
    i
    b
    • 3
    • 3
  • g

    galex

    12/13/2019, 6:48 PM
    Does Dukat replaces the react-wrapper? Does it work already?
    j
    • 2
    • 2
  • g

    galex

    12/14/2019, 5:06 AM
    And what about https://material-ui.com/ ?
    b
    s
    • 3
    • 7
  • b

    Bahaa Kallas

    12/16/2019, 10:01 AM
    #KotlinJS_Gradle when we do build for the first time the project compile with no issues. but when we do build again on top of the previous build everything becomes unresolved ( the code i mean ). so we clean first and then we build and everything looks fine is this the intended behaviour ? clean every time and then perform build i had to mention that after making clean all the code lines becomes unresolved until we do build again
    i
    g
    i
    • 4
    • 7
  • b

    Bahaa Kallas

    12/16/2019, 10:37 AM
    #KotlinJS_Gradle [SOLVED✅] we have kotlinJS project act as a library module for others kotlinJS projects we were able to migrate this project to use the KotlinJs gradle plugin by following the newly added docs and the project compiles successfully with no issues but now we are trying to use this project as a module for the other projects (which they also migrated) the problem happens in the
    "ourLibraryModule":browserWebpack
    task it fails for some dependencies (kotlin-react, kotlin-react-dom, kotlin-extensions, kotlinx-html-js) with the known error message “Module not found: Error: Can’t resolve etc.” we had this issue before when we tried to manage our projects using the kotlin frontend plugin but in the end we end up giving up on that some lines of code states how we doing this right now : in ourModule
    build.gradle
    sourceSets["main"].dependencies{
        api(npm("kotlinx-html","0.6.12"))
        api(npm("@jetbrains/kotlin-extensions","1.0.1-pre.89"))
        api(npm("@jetbrains/kotlin-react", "16.9.0-pre.83"))
        api(npm("@jetbrains/kotlin-react-dom", "16.9.0-pre.83"))
        }
    in parent
    build.gradle
    dependencies {
        implementation(kotlin("stdlib-js"))
        implementation(project(":ourModule"))
    }
    in ourModule
    build.gradle
    we have other dependencies but the webpack task fails only for those does anyone has this project setup and were able to do it by gradle ?
    • 1
    • 1
  • b

    Bahaa Kallas

    12/16/2019, 3:46 PM
    #KotlinJS_Gradle in Kotlin frontend plugin we had this to configure the dev server but how to configure it now using kotlinJs gradle plugin ?
    kotlinFrontend {
        webpackBundle {
            bundleName = "main"
            sourceMapEnabled = true | false   // enable/disable source maps 
            contentPath = file(...) // a file that represents a directory to be served by dev server)
            publicPath = "/"  // web prefix
            host = "localhost" // dev server host
            port = 8088   // dev server port
            proxyUrl = "" | "http://...."  // URL to be proxied, useful to proxy backend webserver
            stats = "errors-only"  // log level
        }
    }
    r
    • 2
    • 1
  • b

    bjonnh

    12/16/2019, 11:25 PM
    https://kotlinlang.org/docs/tutorials/javascript/getting-started-gradle/getting-started-with-gradle.html this isn't up to date is it?
    👍 1
    t
    • 2
    • 5
  • b

    bjonnh

    12/16/2019, 11:55 PM
    they are here in node_modules though
    • 1
    • 1
  • b

    bjonnh

    12/17/2019, 1:49 AM
    Now I am struggling using my kotlin/js code from JS… do I have to declare the functions in a special way so they get recognized?
    a
    • 2
    • 6
  • b

    bjonnh

    12/17/2019, 6:23 AM
    val compileKotlin2Js by getting(org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile::class)
    compileKotlin2Js.apply { kotlinOptions.moduleKind = "commonjs" }
    • 1
    • 5
  • e

    Egor Okhterov

    12/18/2019, 10:02 AM
    What is the use case for
    plugins {
       kotlin("js") version "1.3.61"
    }
    if we can use
    plugins {
       kotlin("multiplatform") version "1.3.61"
    }
    i
    • 2
    • 1
  • b

    breandan

    12/18/2019, 7:21 PM
    In the KotlinConf keynote, Andrey mentioned that quick autoreload was coming soon to Kotlin/JS:

    https://youtu.be/0xKTM0A8gdI?t=2076▾

    Is this functionality currently supported? I was trying to get it running in the context of this tutorial, but so far unsuccessful: https://play.kotlinlang.org/hands-on/The%20State%20of%20Kotlin%20JS/01_Introduction edit: (I have tried updating to
    1.4.0-dev-74
    and enabling Gradle's
    --continuous
    mode) edit #2: It now appears to work, updating to
    1.4.0-dev-74
    was not necessary. Previously was using
    ./gradlew run --continuous
    but
    ./gradlew browserRun --continuous
    was the correct command.
    b
    i
    • 3
    • 8
  • b

    breandan

    12/19/2019, 6:27 AM
    Is there a list of libraries which Dukat can handle? I tried a bunch of libraries which come packaged with TypeScript declarations on NPM, but anything more complicated than
    leftpad
    seemed to fail with various build errors.
    ➕ 2
    u
    • 2
    • 1
  • j

    jw

    12/19/2019, 9:50 PM
    is there anything in place to create an archive of the static resources and final js for deploying a webapp?
    i
    b
    +3
    • 6
    • 9
  • i

    ian.shaun.thomas

    12/20/2019, 6:18 AM
    I needed a noise generator for a simple game I'm making and thought it would be interesting to port one to MPP and see how JS compares to the JVM when significant amounts of math ops are required. Apparently the answer is really poorly. https://github.com/ToxicBakery/Accidental-Noise-Generator If you're interested in watching your browser cry,
    ./gradlew :terrain-preview-web:run
    . Has anyone tried anything similar for say some simple 3d backed by Kotlin JS? Wondering if you saw similar performance concerns doing quat maths or similar at higher frame rates.
    a
    • 2
    • 22
  • e

    Egor Okhterov

    12/20/2019, 9:27 AM
    How do you program moderm web apps? I am reasearching https://github.com/JetBrains/kotlinconf-app and I am scratching my head right now. There are 3 components: 1. Backend 2. Android Client 3. IOS Client Backend just responds to REST API requests and nothing more. Android and IOS client have their own Main() functions so they are fully functional applications themselves. How do you supposed to make a web client in this architecture? Is there supposed to be a second server which provides browsers with
    index.html
    and then javaScript in that index.html makes REST API requests to the original backend? Would you make a separate module for a web client (similar to andoid module) or you just make a
    jsMain
    sourceSet in the backend directory?
    h
    n
    • 3
    • 13
  • f

    fkrauthan

    12/21/2019, 7:55 PM
    I am currently trying to setup a multiplatform project too but I am struggling with embedding the web app. It seems like
    create-react-kotlin-app
    is not the right choice (as that is more for standalone webapps with kotlin). The kotlin frontend plugin seem to be deprecated so I've tried it as plugin
    multiplatform
    and then only have
    js { browser() }
    configured (I assume that is currently the recommended way?). But now when I try to include the dependency to my commons library (which is also
    multiplatform
    and has
    js()
    as one of its target) I receive the error:
    project ':clients:clients-common' is not configured for JS usage
    any idea what I am missing or am I going completely off the rails with my setup?
    👍 1
    b
    i
    • 3
    • 15
  • d

    diesieben07

    12/21/2019, 10:05 PM
    Is there information about whether the new JS backend in 1.4 will bring better interop with the ecosystem, like we have on the JVM side? Some crucial things that are pain-points right now: • Kotlin modules are compiled into one giant .js file instead of compiling each Kotlin file into one .js file (using the module system of the underlying platform, such as commonjs or ecmascript modules). This makes it so tree-shaking and DCE needs to be re-invented from scratch instead of re-using the existing tools. • Calling Kotlin from Javascript is technically possible, but very painful, because the generated code is hard to comprehend (see point one, this would be greatly improved if there was a 1:1 mapping from .kt to .js files) • Calling Kotlin from Typescript is also technically possible, but even more painful, since you need to write declaration files for everything. • Calling Javascript from Kotlin requires writing declaration files (even if there are .d.ts files for the javascript code, see next point) • Typescript / Typescript declarations are entirely unused. The code generated by dukat never works if you have something more complex than "left-pad" (and it can't, because things like
    type Foo = "foo" | "bar"
    cannot be expressed in Kotlin). Another thing that I have noticed is that the kotlinx libraries (ktor, kotlinx.serialization, io) and the stdlib seem to think that they should be polyfilling things themselves if they are missing in the underlying platform. This leads to things like
    <http://kotlinx.io|kotlinx.io>
    requiring an outdated npm library (
    text-encoding
    ) using dynamic calls to require (what if the underlying module system is not commonjs?) if the global
    TextEncoder
    API is not found. Instead it should be the user's responsibility (based on their browser support demands) to load an appropriate polyfill if required. There are great tools (babel and their preset-env) that make it so you can transpile modern Javascript code to run on older browsers and polyfill missing APIs (using core-js). Kotlin should imho use this amazing toolchain, instead of re-inventing the wheel. </rant>
    👍 5
    q
    b
    +2
    • 5
    • 21
  • c

    coolcat

    12/22/2019, 8:24 PM
    Hi all, I created a new Kotlin/JS project using the IntelliJ wizard. I created a file with a
    fun main() {}
    that does a simple print, and an
    index.html
    with
    <script src="project.js"></script>
    . I run the
    jsBrowserRun
    gradle task, and it works, I see the string printed in page console OK. But I also see
    [WDS] Live Reloading enabled.
    So I tried changing the printed string, and I see:
    [WDS] App updated. Recompiling...
    [WDS] Nothing changed.
    Quitting and restarting the server makes the amended string appear. Any hints as to what I can do to make live reloading work correctly
    d
    r
    f
    • 4
    • 3
  • f

    fkrauthan

    12/23/2019, 7:00 AM
    I have another Kotlin JS multiplatform question. If I have a react app that uses the multiplatform plugin. Declares in the kotlin block
    js { browser() }
    how can I run it though the
    kotlin-dce-js
    plugin? Or is that at the moment not supported?
    i
    • 2
    • 1
  • j

    jdemeulenaere

    12/23/2019, 5:49 PM
    How are we supposed to use an NPM dependency using the kotlinjs plugin ? Are we supposed to import it in the html or will it be somehow automagically bundled in one big js ?
    i
    • 2
    • 7
  • j

    jdemeulenaere

    12/23/2019, 5:50 PM
    It's crazy how difficult it is to get started with KotlinJS if we want to use dependencies (e.g. PixiJS in my case)... The documentation really doesn't help at all
    👍 2
    b
    • 2
    • 2
  • e

    Egor Okhterov

    12/24/2019, 10:32 AM
    Is there an RPC plugin that allows to specify interface in common code
    data class User(val id: Int)
    
    @RpcService
    interface UserService {
      suspend fun getUsers(): List<User>
    }
    and generates client for use in Kotlin/JS
    class HomeView : ReactDOMComponent<HomeView.Props, HomeView.State>() {
        prival val userService: UserService by removeServicesPlugin
    
        override suspend fun componentWillMount() {
            super.componentWillMount()
            state.users = userService.getUsers()
        }
    }
    r
    • 2
    • 2
Powered by Linen
Title
e

Egor Okhterov

12/24/2019, 10:32 AM
Is there an RPC plugin that allows to specify interface in common code
data class User(val id: Int)

@RpcService
interface UserService {
  suspend fun getUsers(): List<User>
}
and generates client for use in Kotlin/JS
class HomeView : ReactDOMComponent<HomeView.Props, HomeView.State>() {
    prival val userService: UserService by removeServicesPlugin

    override suspend fun componentWillMount() {
        super.componentWillMount()
        state.users = userService.getUsers()
    }
}
r

Robert Jaros

12/24/2019, 11:20 AM
https://github.com/rjaros/kvision allows something like this for Spring Boot, Ktor and Jooby
If you only want the rpc without the rest of KVision framework take a look here: https://kvision.gitbook.io/kvision-guide/part-3-server-side-interface/external-usage
👍 1
View count: 6