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

    iseki

    01/18/2020, 3:38 AM
    Are there any full document to describe the buildscript mechanism? The gradle and npm is some confusing...
    s
    • 2
    • 1
  • e

    epabst

    01/18/2020, 2:39 PM
    With dukat failing on some dependencies, I've given up (for now) on enabling it during the build of my project. So, I'm left with running it on the command-line. However, due to https://github.com/Kotlin/dukat/issues/206 I can't run the newer versions anymore. I have to go back to version 0.0.14!!! Can someone please fix this?!?
    u
    • 2
    • 3
  • g

    Grantas33

    01/19/2020, 9:51 AM
    Hello. I'm following the newest guide of setting up a Kotlin/JS project with Gradle (https://kotlinlang.org/docs/reference/js-project-setup.html) but I can't seem to import any gradle dependencies in the main.kt file (unresolved reference). Specifically, the JSoup Java library. I can see all the classes of the library in the External Libraries folder in the IDE. I tried importing the same library as a gradle dependency in a Kotlin/JVM project and it works flawlessly. Does anyone have a clue what might be going on?
    s
    i
    • 3
    • 3
  • m

    Max

    01/19/2020, 9:05 PM
    Just ran into the issue described here: https://stackoverflow.com/questions/49331865/kotlin-unsigned-bytes-with-javascript-uint8clampedarray?rq=1 it seems to be a bug?
    i
    • 2
    • 2
  • n

    Nikky

    01/20/2020, 5:19 AM
    is there any chance that the webpack procedure could be improved so that i do not have to open all these folders to look at the code?

    https://i.imgur.com/Zgf1rE8.png▾

    I remember this being not as bad without using webpack, also it would be great if it would not contain the original path to the project on the machine it was built on
    i
    i
    s
    • 4
    • 11
  • i

    iseki

    01/20/2020, 9:27 PM
    Now Kotlin/js generated code without constant pool? There are a lot of string builder with the same structure in bundle.js They are waste lots of space...
    b
    • 2
    • 5
  • e

    egorand

    01/20/2020, 10:19 PM
    I'm trying to set up a multiplatform project to build on a macOS box on Travis CI and started seeing the following JS failures:
    19 01 2020 20:45:29.838:INFO [karma-server]: Karma v4.4.1 server started at <http://0.0.0.0:9876/>
    19 01 2020 20:45:29.842:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
    19 01 2020 20:45:29.848:INFO [launcher]: Starting browser Chrome
    19 01 2020 20:46:29.967:WARN [launcher]: Chrome have not captured in 60000 ms, killing.
    19 01 2020 20:46:31.977:WARN [launcher]: Chrome was not killed in 2000 ms, sending SIGKILL.
    19 01 2020 20:46:34.018:WARN [launcher]: Chrome was not killed by SIGKILL in 2000 ms, continuing.
    
    java.lang.IllegalStateException: command '/Users/travis/.gradle/nodejs/node-v10.15.3-darwin-x64/bin/node' exited with errors (exit code: 1)
    I started with the following configuration:
    kotlin {
      js {
        nodejs()
        browser()
      }
    }
    which AFAIK uses headless Chrome by default, and later changed to this without much luck:
    kotlin {
      js {
        nodejs()
        browser {
          testTask {
            useKarma {
              useChrome()
            }
          }
        }
      }
    }
    I'm unable to reproduce the issue locally. Has anyone had similar failures and managed to work around them?
    f
    s
    j
    • 4
    • 6
  • g

    glade

    01/21/2020, 1:37 AM
    is there a list of transpiling limitations/workarounds for .kt to .js? It looks like standard enums aren’t well supported yet.
    s
    t
    • 3
    • 12
  • b

    Boris Dudelsack

    01/21/2020, 2:47 PM
    how would i correctly write a kotlin wrapper for a React component which resides in a sub path of a module? My approach does not work.
    @file:JsModule("@bootstrap-styled/provider/lib/BootstrapProvider")
    
    package bootstrap
    
    import react.*
    
    @JsName("BootstrapProvider")
    external class BootstrapProvider : Component<RProps, RState> {
        override fun render(): ReactElement?
    }
    n
    • 2
    • 5
  • p

    pjagielski

    01/21/2020, 7:42 PM
    Any good approach to model
    date
    is shared jvm/js DTO ?
    👀 1
    r
    • 2
    • 2
  • g

    glade

    01/21/2020, 9:32 PM
    when using kotlin-dce-js, with the kotlin dsl, I’m having issues with the ‘keep’ parameter working. I would like to keep all code in my package/namespace, and have it prune the kotlin.js and related dependencies based on what my package/namespace is referencing.
    tasks {
        withType<KotlinJsDce> {
            dceOptions {
                devMode = false
            }
            // NOTE: Keep settings don't seem to work at all.  Have tried each individually, and normal package/namespace expressions.
            keep("com.gigwell.PresetType", "com.gigwell", "com.gigwell.*")
        } 
    }
    This is currently being invoked via the webpackTask but I’m guessing this is more my misunderstanding of the dce parameter?
    ⬆️ 1
    👀 2
    i
    b
    • 3
    • 4
  • f

    fcosta

    01/22/2020, 12:20 AM
    I'm getting the following error in my CI and in my local development environment as well:
    > Task :frontend:compileKotlinJs FAILED
    w: Module "kotlin-react-dom" is defined in more than one file
    w: Module "kotlin-react-router-dom" is defined in more than one file
    w: Module "kotlin-react" is defined in more than one file
    w: Module "kotlin-extensions" is defined in more than one file
    w: Module "kotlinx-html-js" is defined in more than one file
    e: warnings found and -Werror specified
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':frontend:compileKotlinJs'.
    > Compilation error. See log for more details
    Any idea how can I debug this error or disable the warnings? I will write the
    build.gradle
    in the thread
    👀 1
    i
    • 2
    • 12
  • l

    Lamberto Basti

    01/22/2020, 1:08 PM
    Hi! Is there any Gradle Kotlin 1.4-dev plugin release that outputs typescript declarations already?
    🇳🇴 1
    i
    b
    s
    • 4
    • 13
  • a

    ankushg

    01/22/2020, 7:09 PM
    We're writing classes in Kotlin which are (1) reliant on enums, and (2) heavily nested. We want to call methods that use/return these classes from our Typescript codebase, where enums are defined as a named set of constants: https://www.typescriptlang.org/docs/handbook/enums.html We find ourselves using
    kotlinx.serialization
    almost exclusively to map from Kotlin Enum Classes to `Int`/`String`s for JS, because our deeply nested classes make it difficult to handwrite methods that accept primitives and map them to Kotlin enum classes. • Is there any way to have Kotlin expose
    enum class
    es as `String`/`Int` values in JS, instead of generated Kotlin classes? • Will 1.4 be able to expose Kotlin enums as legit Typescript enum constants? • Is this something that we need `inline enum class`es to solve?
    t
    • 2
    • 4
  • f

    fcosta

    01/23/2020, 1:44 AM
    I'm trying the
    Dukat
    in order to allow the automatic conversion of TypeScript declaration files and I'm having some issues. I will post in the thread!
    👀 1
    i
    e
    • 3
    • 14
  • j

    Jue

    01/23/2020, 8:33 PM
    We have a JS library that needs to be loaded on the page to render some content. We are looking into moving some pieces of this library to KotlinJS. As such we have noticed that render performance on the page is very sensitive to our library's size, so we want to keep it as small as possible without any external dependencies. But so far it seems like JS generated by Kotlin has dependecy on `kotlin.js`, which needs to be loaded in browser before transpiled JS. We tried minifying+gziping kotlin.js, and it is still ~150kb in size, which is a deal breaker for us. So I wanted to confirm here if there is any possible way to not have to load `kotlin.js` and instead inline all the dependecies in the transpiled JS itself, or load only needed parts of it. Thanks.
    g
    i
    • 3
    • 4
  • t

    tylerwilson

    01/24/2020, 3:13 PM
    Anybody have any links to up-to-date project using JS, DCE and hopefully Ktor/Serialization? I started from the IntelliJ template and it is hardly a decent starting point.
    r
    s
    +4
    • 7
    • 31
  • g

    Grantas33

    01/26/2020, 8:24 AM
    build/js/packages_imported/ktor-ktor-client-core/1.3.0/ktor-ktor-client-core.js
    Module not found: Error: Can't resolve 'abort-controller' in 'build\js\packages_imported\ktor-ktor-client-core\1.3.0'
    build/js/packages_imported/ktor-ktor-io/1.3.0/ktor-ktor-io.js
    Module not found: Error: Can't resolve 'text-encoding' in 'build\js\packages_imported\ktor-ktor-io\1.3.0'
    I'm having these errors in the browser console of my KotlinJS project. I'm not using ktor as a direct dependency - I use a kotlin multiplatform library which uses ktor. I've had the same errors when developing the aforementioned library, and after adding jsMain npm dependencies in the library's build gradle file like this:
    api(npm("text-encoding"))
    api(npm("abort-controller"))
    the errors dissapeared from the library. However, they still do exist in my KotlinJS project which uses this library. What could be the issue here?
    i
    • 2
    • 2
  • t

    Tobi

    01/27/2020, 7:38 AM
    Hey folks, I want to add kotlin-styled (https://github.com/JetBrains/kotlin-wrappers/tree/master/kotlin-styled) to my existing kotlin.js project, but gradle fails to resolve the dependencies through npm 🤔
    error Couldn't find package "@jetbrains/kotlin-inline-style-prefixer@1.0.0-pre.89" required by "cats-js@1.0.0-SNAPSHOT" on the "npm" registry.
    That's how I configured the dependency:
    kotlin {
        target {
            browser {}
            nodejs {}
        }
    
        sourceSets {
            main {
                dependencies {
                    implementation kotlin('stdlib-js')
                    implementation kotlin('test-js')
    
                    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:0.14.0"
                    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.2'
                    implementation "io.ktor:ktor-client-js:1.2.6"
                    implementation "io.ktor:ktor-client-json-js:1.2.6"
                    implementation("io.ktor:ktor-client-serialization-js:1.2.6")
    
                    implementation(npm("core-js", "^2.0.0"))
                    implementation(npm("@jetbrains/kotlin-react", "16.9.0-pre.83"))
                    implementation(npm("@jetbrains/kotlin-react-dom", "16.9.0-pre.83"))
                    implementation(npm("@jetbrains/kotlin-extensions", "1.0.1-pre.67"))
                    implementation(npm("@jetbrains/kotlin-extensions", "1.0.1-pre.67"))
                    implementation(npm("@jetbrains/kotlin-styled", "1.0.0-pre.89"))
                    implementation(npm("@jetbrains/kotlin-css", "1.0.0-pre.89"))
                    implementation(npm("@jetbrains/kotlin-inline-style-prefixer", "1.0.0-pre.89"))
    
                    implementation(npm("react", "16.8.3"))
                    implementation(npm("react-dom", "16.8.3"))
                    implementation(npm("kotlinx-html", "0.6.12"))
                    api(npm("text-encoding","0.7.0"))
                }
            }
        }
    }
    Furthermore I added the alias as I've done it previously for other dependencies:
    // workaround for <https://youtrack.jetbrains.com/issue/KT-31807>
    config.resolve.alias = {
        'kotlin-css-js': '@jetbrains/kotlin-css-js',
        'kotlin-extensions': '@jetbrains/kotlin-extensions',
        'kotlin-react': '@jetbrains/kotlin-react',
        'kotlin-react-dom': '@jetbrains/kotlin-react-dom',
        'kotlin-styled': '@jetbrains/kotlin-styled',
        'kotlin-css': '@jetbrains/kotlin-css',
        'kotlin-inline-style-prefixer': '@jetbrains/kotlin-inline-style-prefixer',
        'kotlinx-html-js': 'kotlinx-html',
    };
    Any idea what could be the problem? Thanks in advance!
    i
    i
    • 3
    • 4
  • a

    AJ Alt

    01/27/2020, 6:35 PM
    If I'm configuring my JS target using the MPP plugin with
    js { nodejs {} }
    , how do I access Node global objects like
    process
    etc. from the
    jsMain
    source set?
    👀 1
    i
    • 2
    • 5
  • b

    Big Chungus

    01/28/2020, 1:26 PM
    Anyone encountered this issue with dukat?
    $ dukat index.d.ts
    /usr/local/lib/node_modules/dukat/lib/converter.js:401
            var packageNameFragments = sourceFile.fileName.split("/");
                                                  ^
    
    TypeError: Cannot read property 'fileName' of undefined
    z
    • 2
    • 3
  • b

    Big Chungus

    01/28/2020, 1:55 PM
    Anyone encountered issues where DCE seemingly removes something vital? I'm getting
    Uncaught TypeError: g is not a function
    after running dce on my page. Any suggestions how to investigate/resolve this?
    i
    • 2
    • 5
  • b

    Brandon Saunders

    01/30/2020, 1:46 AM
    does anyone know if "internal" functions will work correctly with the Typescripting work coming in next release? We ran into an issue where our functions defined as internal couldn't be JS unit tested, because they're not emitted at all by the JS output
    g
    s
    • 3
    • 6
  • p

    prab

    01/30/2020, 5:53 AM
    I am new Kotlin and Kotlin/JS. I am trying to setup a webapp project that takes the javascript output file of a Kotlin multiplaform project, webpack bundle it with kotlin.js, ktor-ktor-client-js.js, kotlinx-serialization-kotlinx-serialization-runtime.js etc and run it, run DCE/tree-shaking on it, and output the final bundle. I am finding it very difficult to setup the build.gradle file to do these. Kotlin’s example project for DCE tool is couple years old, so thats not much help. Can someone point me to some example project whose build.gradle I could copy from to achieve what I described above.
    k
    i
    r
    • 4
    • 4
  • j

    Jue

    01/30/2020, 7:42 AM
    Is there a way to run Kotlin-DCE on a shared.js library(build out of a multiplatform project) which has dependency on kotlinx-serialization and ktor-client. Goal is to remove all dead code from kotlinx-serialization and ktor-client js files that are not needed by the shared.js. Thanks.
    i
    • 2
    • 1
  • c

    corneil

    01/30/2020, 8:32 AM
    s it possible to use kotlin js with target { browser{}} where you define npm dependencies in the gradle build and your kotlin is converted to js and the related dependencies are packaged so that there is a simple list of js files to include in a page?
    i
    • 2
    • 2
  • s

    Sean Keane

    01/30/2020, 9:09 AM
    Does anybody have a sample multi platform app with JS ?
    i
    • 2
    • 2
  • j

    Jess Brent

    01/30/2020, 2:14 PM
    is it possible to create a kotlin library that can be used for android/jvm and transpile to js without using multiplatform? i can’t find any resources on this because everyone seems to be using multiplatform 😅
    s
    • 2
    • 2
  • j

    Janelle Fullen

    01/30/2020, 9:53 PM
    I'm attempting to try out (experimental) Typescript annotations using the following compiler flags that I added to my gradle:
    -Xir-produce-js
    -Xgenerate-dts
    However, the compiler can't find the JsName JsExport annotation when I try to use it. I'm using Kolin 1.3.60. Am I missing something?
    s
    • 2
    • 7
  • k

    Kenneth Andersson

    01/31/2020, 9:22 AM
    Hi all, does anyone know if there is a way to configure the default timeout of the mocha runner used for js/nodejs target ? We are hitting the default timeout of 2s on one of our testcases
    👍 1
    i
    y
    • 3
    • 3
Powered by Linen
Title
k

Kenneth Andersson

01/31/2020, 9:22 AM
Hi all, does anyone know if there is a way to configure the default timeout of the mocha runner used for js/nodejs target ? We are hitting the default timeout of 2s on one of our testcases
👍 1
i

Ilya Goncharov [JB]

02/02/2020, 7:46 AM
Hi, if you use nodejs You can set it in build script
nodejs {
   testTask {
      useMocha {
         timeout = "10s"
      }
   }
}
👍 1
k

Kenneth Andersson

02/03/2020, 8:07 AM
Thanks!
y

yogi

05/07/2020, 12:32 PM
FWIW, if someone comes across this thread and wants to do the same for browser tests (that use
karma
) , here is how I did it: • Create
karma.config.d
in the project directory • Atleast kotlin-gradle
1.3.71
checks this directory for an
js
files and blindly appends them to the generated
karma.conf.js
[1] • Create a file
karma.config.d/mocha-timeout-override.s
with following content [2]
config.set({
  "client": {
    "mocha": {
      "timeout": 5000
    },
  },
});
[1] https://github.com/JetBrains/kotlin/blob/7fe66d3456a2e51e5bf228497e81b28a6367766c/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/testing/karma/KotlinKarma.kt#L44 [2] http://blog.jonathanargentiero.com/overriding-karma-mocha-default-timeout-2000ms/
View count: 7