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

    russhwolf

    04/05/2020, 1:08 AM
    Is it possible to configure separate browser and nodejs sourceSets within a single js target? Thinking about a multiplatform context where they want to share some code but not all.
    r
    • 2
    • 2
  • k

    kartoffelsup

    04/05/2020, 8:53 AM
    How do I 'copy' my resources over to the webpack directory? Under 'build/js/packages/<project>'? I'm trying to use the HtmlWebpackPlugin with a template index.ejs but I don't know how I can pass the index.ejs from my resources folder into that project dir? It just places it under 'processedResources' which I do not want.
    t
    • 2
    • 3
  • p

    p2000t

    04/05/2020, 10:14 AM
    I am experimenting with Kotlin 1.4-M1, and live reload with the IR compiler. On a "Hello, World" project reload takes ~1 second on my laptop, which is really nice. However, if I add some code (~5K lines), the reload takes ~10 to 20 seconds, even if I change only one line in the main class (i.e. code with no relevant dependencies). Is this expected, or should I get faster reload times? For reference, the generated JavaScript file is approximately 1Mb in size. I am asking, because I am trying to decide whether I should make the frontend application in React/TypeScript and leave some critical code in Kotlin, or whether I can do all frontend development in Kotlin (which would, of course, be preferable).
    i
    • 2
    • 2
  • p

    pablisco

    04/06/2020, 8:27 AM
    With gradle kts dsl, there are generated sources that are very useful. so that instead of doing
    "implementation"("dependency")
    we can do
    implementation("dependency")
    . Does anyone (maybe from JB) knows if there are plans to, similarly, generate type safe mappings from npm dependencies on Kt JS? It would make it significantly easier to interop with js without having to create all the mappings manually (or wait for someone else to make a wrapper 🙃)
    b
    p
    • 3
    • 14
  • g

    galex

    04/06/2020, 11:04 AM
    Hello, did someone manage to use the generated
    d.ts
    file in a react app for example? Basically, what I don’t understand is that it declares the root project as a
    namespace
    instead of a
    module
    so when I try to import use the
    d.ts
    and import my module I get the error
    lib.d.ts is not a module
    .
    d
    • 2
    • 2
  • g

    galex

    04/06/2020, 3:00 PM
    Is there a way to have the DCE task run but without minifying? I want to get the least needed readable code possible!
    r
    t
    i
    • 4
    • 7
  • l

    llsouder

    04/06/2020, 4:23 PM
    Can someone point me to kotlin browser side websockets? Google searching turns up lots of server side code and tutorials which use regular javascript on the browser side. I am finding it extremely challenging to find information about kotlin js, in fact I don't even know if that is a thing. I am using the html DSL in a create-kotlin-react project. Maybe I came to this party too late. Need a break through.
    c
    r
    • 3
    • 9
  • a

    Andrew

    04/07/2020, 5:02 AM
    Using React, is it possible to have a function in an RState interface that modifies additional state based on logic? I'm converting a JS example to Kotlin and they wrap all the state in a custom hook with at least 1 inner function that conditionally set some state values based on logic. I tried doing that in Kotlin and it didn't seem to work. Not a big deal but seems like a cleaner way to separate code by having state logic directly in the interface that defines it. An example below. setState { someFunction(newValue) // member of RState interface that sets 1 or more values }
    i
    s
    • 3
    • 5
  • p

    patrickdelconte

    04/07/2020, 7:50 AM
    In a gradle multi-module setup with the kotlin js plugin executing tests from Idea does not work. Running gradle tasks from the ui does not work either. Both work fine on the command line. Both print the following error when run from the IDE
    Build file '.../hydrants/hydrants-cloud-functions/build.gradle.kts' line: 1
    * What went wrong:
    Plugin [id: 'org.jetbrains.kotlin.js'] was not found in any of the following sources:
    - Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
    - Plugin Repositories (plugin dependency must include a version number for this source)
    line 1 of is
    _kotlin_(*“js”*)
    inside the plugins block. It is almost as if Idea tried to parse the gradle file as if it was a standalone project
    i
    • 2
    • 6
  • f

    Franco

    04/08/2020, 7:23 AM
    Hi everyone, I'm having some issues building a Kotlin/JS React app in production mode (it works when running it locally in dev mode), if anyone can give me a hand it'd be greatly appreciated as I'm quite new with JS. I wrote a post in the Kotlin forum (https://discuss.kotlinlang.org/t/kotlin-js-project-doesnt-build-properly-for-production/17022) as it's a lot of text to put here.
    👀 1
    ✔️ 1
    i
    • 2
    • 2
  • j

    Jess Brent

    04/08/2020, 2:35 PM
    hey guys, i posted this in #multiplatform yesterday, and i’m guessing that i’m running into issues here because js doesn’t support non-local returns? does anyone know how I can write this in a manner that will work on js? function:
    inline fun <reified T> withResult(
        method: Result<T>,
        onFailure: (errors: List<Throwable>) -> Unit
    ): T {
            @Suppress("IMPLICIT_CAST_TO_ANY")
            val methodResult = when (method) {
                is Result.Success -> { method.t }
                is Result.Failure -> { onFailure.invoke(method.errors) }
            }
            return methodResult as T
    }
    usage:
    val r = withResult(method) { return Result.Failure(it) }
    i can get this function to work on jvm, however it does not work on js. it results in a
    ClassCastException
    the transpiled js appears to show that instead of invoking
    onFailure
    it is only assigned to
    methodResult
    . also, this is a custom sealed class
    Result
    not
    kotlin.Result
    t
    r
    +2
    • 5
    • 56
  • s

    steamstreet

    04/09/2020, 4:21 AM
    I have been working on an app with one JS client and the server. I have split that into two separate clients, each as their own JS application, using the js plugin. However, with both in the same gradle root project (each are a subproject), I am getting “NPM Dependencies already resolved and installed” when building. If I build them separately, they each build fine, but when run as part of a larger build process, I get that error. Any insights?
    a
    i
    • 3
    • 4
  • r

    Rob Murdock

    04/09/2020, 3:01 PM
    Is making a “node exec” task generally available part of the js plugin plan (for running things installed by an npm dependency)? I have a few node programs I need to run, but to do that in gradle right now I’m juggling both the kotlin auto-installed node and the “com.github.node-gradle.node” plugin… which seems silly and causes multiple node installs.
    c
    r
    • 3
    • 9
  • k

    Kiryushin Andrey

    04/09/2020, 6:19 PM
    Hi, I have a problem with webpack build within a multiplatform project. The frontend build fails with the following error:
    Execution failed for task ':jsBrowserProductionWebpack'.
    >                 Process 'webpack' returns 2
    I've narrowed the problem down to the usage of
    io.ktor.client.HttpClient
    class. This error appears if I instantiate it or obtain its reflection descriptor in any part of the js source set and goes away if I remove all references of this class from the source set. My Kotlin multiplatform plugin version is
    1.3.71
    and Ktor version is
    1.3.2
    . I have dependencies on both
    io.ktor:ktor-client-core
    and
    io.ktor:ktor-client-js
    in my jsMain source set. Any help is appreciated - maybe anyone has ideas on why this is happening or at least how to gain more insight into what is happening during the webpack build.
    r
    i
    • 3
    • 5
  • r

    Rob Murdock

    04/09/2020, 6:37 PM
    Is anybody else having big memory usage spikes when running the browserTest task?
    a
    i
    • 3
    • 15
  • d

    Darran

    04/10/2020, 3:21 AM
    guys - i convinved my company to write a big piece of their app in kotlin/js and we are going to release soon - everything is working fine, but I am scared - did I make a big mistake :/
    l
    h
    +3
    • 6
    • 15
  • n

    Nicole

    04/10/2020, 6:28 PM
    For someone that’s only using the community edition of Intellij for a personal project, what’s the best way to write a Kotlin/JS project that can utilize a nice REPL style? My first thought was to try and run the code via node.js during development/debugging, but that doesn’t seem like it’s an option? My next thought was to just build it as a multiplatform jvm/js project, and just run the jvm version during development, and deploy the js at the end? Is there a better way, given I don’t actually want to target the jvm? ^^
    a
    • 2
    • 7
  • r

    Robert Jaros

    04/11/2020, 1:24 AM
    Is there any way to force a specific version of npm dependency globally? If I specify the version explicitly in gradle it's being used inside a "local"
    node_modules
    , but I need to force this in "project" `node_modules' (
    built/js/node_modules
    ).
    t
    • 2
    • 9
  • b

    bod

    04/11/2020, 4:59 PM
    Hello, World! I'm having trouble with
    is
    returning false when it should return true 😛 I'm using a
    sealed class
    for a state, which has a few `object`s and `data class`es as subclasses, and a
    when
    like so:
    when (state) {
        is Foo -> doSomethingFoo()
        is Bar -> doSomethingBar()
    }
    etc. Any suggestions?
    a
    a
    • 3
    • 18
  • y

    yousuf.haque

    04/11/2020, 7:36 PM
    Here’s a codesample anyway: https://github.com/yousuf-haque/kotlin-js-subdirectory-example
    t
    • 2
    • 4
  • f

    Franco

    04/12/2020, 12:36 AM
    Hi everyone, I was wondering if there is a way to create different build variants in Gradle for a Kotlin/JS project? I come from an Android background so I'm looking for something similar to "product flavors" where I can have a different configuration for a development and a production build (e.g., using different API base URLs). I know that we can use development and production runs with
    browserDevelopmentRun
    and
    browserProductionRun
    but that feels like a "debug" and "release" thing where the former doesn't do any optimisations and the latter does.
    t
    a
    i
    • 4
    • 8
  • f

    Franco

    04/12/2020, 4:24 AM
    Hi again, is there an easy way to convert Kotlin data classes (or normal classes) to JS objects? I have tried the
    Any.asJsObject()
    functions but that doesn't seem to do the trick. My use case is that I'm trying to use the Firestore JS library to save some data but it only receives JS objects as input when trying to save data and I'm using normal Kotlin classes to handle this same data in the we app logic.
    t
    • 2
    • 11
  • y

    yawkat

    04/12/2020, 9:09 AM
    Is there anything special about enum support in kotlin.js? I've been having some issues where enums seem to "devolve" into strings, which leads to errors when accessing their properties or using when statements on them
    t
    • 2
    • 5
  • c

    Chaitanya Chunduri

    04/14/2020, 2:29 PM
    HI everyone, I'm preparing an a demo application for the purpose giving a talk, then i'm getting issues saying kotlin-styled is not being loaded, full details to the issue are mentioned in the below link, Kotlin-Styled not loading in the app, could you please help me to solve this. Thank you
    i
    • 2
    • 2
  • a

    Ana Redmond

    04/15/2020, 4:23 PM
    Is there a way to change the name of the js file/lib that Kotlin Multiplatform build creates?
    :yes: 2
    t
    • 2
    • 13
  • d

    Daniel

    04/17/2020, 12:50 PM
    Hello. I went over the tuturial available at https://play.kotlinlang.org/hands-on/Building%20Web%20Applications%20with%20React%20and%20Kotlin%20JS/01_Introduction and after reading it my first exercise was to use one of the components available in the react bootstrap lib (https://react-bootstrap.github.io/getting-started/introduction). I created a
    .kt
    file for the
    Alert
    component and everything works fine exept importing the CSS resources. For now I dealt with this by importing the CSS file directly in html but I am wondering what would be the proper way of saying the following:
    {/* The following line can be included in your src/index.js or App.js file*/}
    
    import 'bootstrap/dist/css/bootstrap.min.css';
    r
    r
    • 3
    • 11
  • m

    magnumrocha

    04/18/2020, 11:16 AM
    hello guys, is there any Static Content Generator built in kotlin-js ?
    👀 1
    n
    n
    • 3
    • 22
  • k

    Kit

    04/20/2020, 6:05 PM
    Hello People, I am working on a multiplatform project (kotlin version 1.3.61) and I am unable to access the indexedDb. Is indexedDb natively supported? If anyone has any insight on this and can share I would be very grateful 🙏
    t
    a
    • 3
    • 4
  • s

    shama

    04/23/2020, 5:13 AM
    Hi! Is there a reason why properties on classes exported to JS are not enumerable? I noticed in 1.4-M1, if I have:
    @JsExport
    class UIComponent {
        val tagName: String = "h1"
    }
    It creates the following JS:
    function UIComponent() {
      this._tagName = 'h1';
    }
    UIComponent.prototype._get_tagName_ = function () {
      return this._tagName;
    };
    Object.defineProperty(UIComponent.prototype, 'tagName', {
      get: UIComponent.prototype._get_tagName_
    });
    Consuming the JS with:
    const h1 = new UIComponent(); Object.keys(h1);
    only gives me the underscore prepended property
    ["_tagName"]
    and
    for (let p in h1)
    will enumerate through the
    _tagName
    and
    _get_tagName_
    properties but skip over the property I want,
    tagName
    . I was expecting the opposite, where
    _tagName
    is not enumerable and
    tagName
    is enumerable. The reason is lots of JS libs rely on
    hasOwnProperty()
    and being able to enumerate through properties on an object considered its own. My specific use case is
    Ember.Component.extend(new UIComponent())
    doesn’t work because it cannot enumerate and find the properties I have defined. I think at the very least,
    enumerable: true
    should be added to
    defineProperty()
    or even better, the public properties get set in the constructor and the behind the scenes ones use
    defineProperty()
    and keep the default
    enumerable: false
    . But maybe there is a reason they are the way they are. Thanks!
    d
    s
    t
    • 4
    • 5
  • g

    Grantas33

    04/23/2020, 11:39 AM
    Hello. Has anyone encoutered a similar error when building a kotlin.js project?
    error Couldn't find any versions for "kotlin" that matches "%%%KOTLIN_VERSION!!!"
    > Task :kotlinNpmInstall FAILED
    Execution failed for task ':kotlinNpmInstall'.
    >                 Process 'Resolving NPM dependencies using yarn' returns 1
    My build.gradle.kts: `
    repositories {
        maven("<https://kotlin.bintray.com/kotlin-js-wrappers/>")
        mavenCentral()
        jcenter()
    }
    
    dependencies {
        implementation("org.jetbrains:kotlin-styled:1.0.0-pre.93-kotlin-1.3.70")
        implementation(npm("styled-components"))
        implementation(npm("inline-style-prefixer"))
    
        implementation("org.jetbrains:kotlin-react:16.13.0-pre.93-kotlin-1.3.70")
        implementation("org.jetbrains:kotlin-react-dom:16.13.0-pre.93-kotlin-1.3.70")
        implementation("com.soywiz.korlibs.klock:klock-js:1.7.3")
    
        implementation(npm("react", "16.13.1"))
        implementation(npm("react-dom", "16.13.1"))
        implementation(project(":common"))
    }
    
    kotlin.target.browser { }
    I've tried removing all of the npm dependencies, yet the same error persists
    i
    • 2
    • 2
Powered by Linen
Title
g

Grantas33

04/23/2020, 11:39 AM
Hello. Has anyone encoutered a similar error when building a kotlin.js project?
error Couldn't find any versions for "kotlin" that matches "%%%KOTLIN_VERSION!!!"
> Task :kotlinNpmInstall FAILED
Execution failed for task ':kotlinNpmInstall'.
>                 Process 'Resolving NPM dependencies using yarn' returns 1
My build.gradle.kts: `
repositories {
    maven("<https://kotlin.bintray.com/kotlin-js-wrappers/>")
    mavenCentral()
    jcenter()
}

dependencies {
    implementation("org.jetbrains:kotlin-styled:1.0.0-pre.93-kotlin-1.3.70")
    implementation(npm("styled-components"))
    implementation(npm("inline-style-prefixer"))

    implementation("org.jetbrains:kotlin-react:16.13.0-pre.93-kotlin-1.3.70")
    implementation("org.jetbrains:kotlin-react-dom:16.13.0-pre.93-kotlin-1.3.70")
    implementation("com.soywiz.korlibs.klock:klock-js:1.7.3")

    implementation(npm("react", "16.13.1"))
    implementation(npm("react-dom", "16.13.1"))
    implementation(project(":common"))
}

kotlin.target.browser { }
I've tried removing all of the npm dependencies, yet the same error persists
i

Ivan Kubyshkin [JetBrains]

04/23/2020, 2:09 PM
What version of Kotlin do you use? Can you attach a link to your project?
g

Grantas33

04/23/2020, 2:11 PM
Sorry for your time, I already figured it out. I was using the klock library which uses kotlin 1.3.61, when my project uses 1.3.70. Upgrading to a klock 1.9.1, whch uses kotln 1.3.70 elimnated the error.
👍 2
View count: 6