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

    Tristan Blakers

    11/03/2020, 1:42 AM
    Is there a way to get extension functions to work when called from javascript?
    @JsName("TestClass")
    data class TestClass(val num: Int) {
        fun half() = num / 2
    }
    
    @JsName("doubleNum")
    fun TestClass.doubleNum() = this.num * 2
    In the above, I can create instances of TestClass and use the half method, but (perhaps unsurprisingly) the doubleNum() method doesn't exist on the object...
    b
    • 2
    • 3
  • a

    Alexander Klimov

    11/03/2020, 10:04 AM
    Has anybody faced with something like the next error?
    > Task :kotlinNpmInstall
    `warning workspace-aggregator-17c92542-f070-464f-b6a6-41dbd344139e > foo > plotly.js > point-cluster > bubleify > buble > os-homedir@2.0.0: This is not needed anymore. Use
    require('os').homedir()
    instead.`
    error An unexpected error occurred: "EPERM: operation not permitted, unlink 'C:\\Users\\Dell\\AppData\\Local\\Yarn\\Cache\\v6\\npm-plotly-js-1.54.6-ed021aa8da85759c69602c97bd3dab2b09eeec22-integrity\\node_modules\\plotly.js\\.yarn-tarball.tgz'"
    . I've tried to google, but nothin about it in Kotlin context. As fas as I understand, it's due to Win 10 prevents some disk-operations on system disk (C:) Does anybody workaround for this case? Can I specify yarn's cache directory on another disk then C:
    a
    • 2
    • 3
  • b

    Björn Mayer

    11/03/2020, 10:18 AM
    How can I prevent my Kotlin classes getting renamed in JS when executing the
    browserProductionWebpack
    build?
    ✅ 1
    a
    t
    • 3
    • 7
  • m

    Marc Knaup

    11/04/2020, 12:47 AM
    Is there a way to use resource hashing? So that I get
    assets/image.<somehash>.png
    for example and can also reference it properly.
    🔥 2
    t
    • 2
    • 4
  • m

    Marc Knaup

    11/04/2020, 3:11 AM
    Now I have Webpack and Kotlin both copy all resources, but into different directories 😴 Is there a way to prevent Kotlin from copying resources to the
    distribution
    ? And
    devServer
    also shouldn’t serve files from the resources folder directly. Edit 1: I need to keep the folder marked as a resources folder. Edit 2: Mhh,
    index.html
    is a notable exception because it’s not copied by a Webpack loader.
    No longer necessary.
    t
    • 2
    • 5
  • h

    hallvard

    11/05/2020, 12:02 PM
    Building my project with Gradle, I can use
    js { moduleName = "myModuleName" }
    to adjust my module name, but according to the docs, this «_does not affect the webpacked output_». In the top of the produced .js file in my project, I find this:
    root["jsapi"] = factory()
    . Now how do I go about having Gradle change that string from the project name (jsapi) into something else?
    s
    • 2
    • 12
  • y

    Yan Pujante

    11/05/2020, 5:38 PM
    I have a kotlin js project (which was bootstrapped from IDEA wizard) with a very simple build file:
    ...
    kotlin {
        js(IR) {
            browser {
                binaries.executable()
                webpackTask {
                    cssSupport.enabled = true
                }
                runTask {
                    cssSupport.enabled = true
                }
            }
        }
    }
    My project includes a bunch of files that I would like to bundle into a zip file during the build and made available to both the run mode and prod mode (I am using jszip from kotlin to load the zip file but the zip file needs to be generated). Can somebody point me into what I should do to make this happen?
    a
    • 2
    • 1
  • s

    steamstreet

    11/05/2020, 10:20 PM
    Is there a reason that the webpack tasks are by default always enabled? When I’m writing a multiplatform library that includes Javascript (or even just a JS lib), there doesn’t seem to be a really good reason to run webpack. Am I missing something? Could this at least be linked to the explicitApi() setting? It’s become somewhat tiresome to always be putting
    tasks["jsBrowserWebpack"].enabled = false
    in my build files for JS libraries.
    t
    a
    a
    • 4
    • 10
  • c

    christophsturm

    11/06/2020, 10:47 AM
    i have a kotlin-js project as part of a multiproject build, and webpack does not seem to generate an output file. also some build files seem to be in <root>/build and others in <root>/js/build (js is the kotlin-js project
    • 1
    • 1
  • m

    Marc Knaup

    11/06/2020, 5:23 PM
    Using inline classes as parameter type or return type of external declarations is not supported
    Noooo 😭 Will this limitation stay?
    a
    t
    • 3
    • 29
  • p

    patrickdelconte

    11/06/2020, 7:59 PM
    Anyone know how to pass command line arguments to my kotlin node application? I had no luck with either
    ./gradlew run myargs
    or
    ./gradlew run --args='myargs'
    b
    • 2
    • 19
  • a

    ankushg

    11/06/2020, 8:54 PM
    Hey gang, We're trying to complete our migration to Kotlin 1.4 and kotlinx.serialization 1.0.1 (using the legacy compiler) We consume our Kotlin/JS libraries as npm artifacts, but the
    kotlinx-serialization-kotlinx-serialization-*-jsLegacy
    module names are broken with npm because npm doesn't support uppercase characters in package names Does anyone know of a workaround? Is this being worked on?
    b
    • 2
    • 13
  • b

    Big Chungus

    11/07/2020, 5:12 PM
    I've raised bugs on yarn and new npm repos regarding incorrect bundledDependencies resolution when installing packages. Can you guys vote on them to get it fixed, since bundled dependencies are pretty much required for publishing kotlin/js packages to npm given how many of kotlin/js libraries are not being published there.
    👍 1
    r
    • 2
    • 5
  • y

    Yan Pujante

    11/07/2020, 7:21 PM
    I have a simple kotlin/javascript project
    kotlin {
        js(IR) {
            browser {
                binaries.executable()
                webpackTask {
                    cssSupport.enabled = true
                }
                runTask {
                    cssSupport.enabled = true
                }
            }
        }
    }
    which automatically picks up all resources from
    src/main/resources
    . How do I add another folder?
    b
    • 2
    • 9
  • a

    Andrew

    11/08/2020, 4:31 AM
    I'm new to kotlin js and trying to get a KMP project to work for the first time as an exported JS module/file. I can build it without errors now but trying to load the myproject.js in a chrome console I get this error. I am using reflection in one place that is just returning a KClass which says is supported. Is there anything else I need to do? Uncaught TypeError: Kotlin.kotlin.reflect.js is undefined
    a
    b
    • 3
    • 49
  • m

    Marc Knaup

    11/08/2020, 5:17 PM
    I know I’ve said that I’ll not use Kotlin React in production yet… Well, turns out I’m crazy enough to do. I’m currently developing our startup website with Kotlin React and so far it’s much more fun than having to use JS or TS 🙂 I think there’s a lot of potential for Kotlin React but there’s also much room for improvements. Anyone else using it in production yet?
    👍 4
    🎉 6
    ⭐ 2
    n
    v
    +4
    • 7
    • 19
  • b

    bbaldino

    11/09/2020, 8:14 PM
    I'm just getting started and have a dumb question I can't seem to find the answer to: do I need to do anything special to integrate with a js lib pulled from npm? I'm trying to do something with highcharts, and have added the dependency, but not sure the process on what else I need to do to use it (no symbols or anything seem to resolve). This is in a new kotlinjs project.
    r
    d
    • 3
    • 33
  • s

    Slackbot

    11/10/2020, 11:28 AM
    This message was deleted.
    b
    h
    • 3
    • 2
  • r

    robstoll

    11/10/2020, 8:45 PM
    Is there a way to configure mocha when I am using
    kotlin{ js { nodejs() }}
    I would like to see more than just the first line in case of a failure in the console
    r
    • 2
    • 2
  • y

    Yan Pujante

    11/10/2020, 10:46 PM
    Sorry for another stupid question: I have a simple kotlin/js project.
    kotlin {
        js(IR) {
            browser {
                binaries.executable()
                webpackTask {
                    cssSupport.enabled = true
                }
                runTask {
                    cssSupport.enabled = true
                }
            }
        }
    }
    When I run the
    build
    target it builds and put the result under
    <buildDir>/distributions
    . I obviously can use
    File(buildDir, "distributions")
    to access this folder, but I am sure there is some magic variable to get to it. And I suppose my second question/frustration is how on earth can you discover this kind of things without having to ask around in the slack channel? Although I am a big fan of gradle in general, I find it so not discoverable...
    r
    t
    • 3
    • 12
  • d

    Dmitry Romanov [JB]

    11/11/2020, 8:49 AM
    Hey folks! As you all know well we are working on moving our new IR compiler backend to the Beta stage (KT-42289). As part of this task, i’m trying to reach the third-party library maintainers to ask them to provide compatibility with the new backend (support both-mode). Or get a list of problems that stop them from doing it. You can really help me by looking at the list below and pointing out third party (not Kotlin or JetBrains) libraries/artifacts, that are not on it, but are used in your projects: •  KVision  •  Fritz2  •  KorGE  •  Doodle  •  Plotly.kt  •  Kmath  •  Kotest •  samgarasx/kotlin-js-wrappers •  redux-kotlin •  vue-kotlin •  kotlin-material-ui •  yested_fw •  kvdom •  Kodein-DI •  Koin
    👀 1
    s
    a
    +8
    • 11
    • 28
  • c

    CLOVIS

    11/11/2020, 11:37 AM
    I'm a bit new to JS... I'm trying to unit test a function that takes a
    org.w3c.files.File
    as argument, but I don't know how to build one from JS (on JVM I could just
    new java.io.File("path")
    but I've heard that's not possible on JS?)
    n
    • 2
    • 42
  • m

    Marc Knaup

    11/11/2020, 5:01 PM
    Why can’t I create new instances of this from Kotlin?
    @JsModule("@emotion/stylis")
    @JsNonModule
    external class Stylis(
    	options: StylisOptions = definedExternally,
    )
    
    val stylis = Stylis() // runtime: Stylis is not a constructor
    At runtime
    Stylis
    is actually a Module and
    Stylis.default
    is the actual class 🤔
    b
    t
    • 3
    • 41
  • m

    Marc Knaup

    11/11/2020, 7:53 PM
    Ugh, is refactoring not supported across multiple Kotlin/JS modules?
    a
    • 2
    • 4
  • m

    Marc Knaup

    11/12/2020, 2:33 AM
    Why can’t I use
    suspend fun foo(): T
    instead of
    fun foo(): Promise<T>
    in an
    external interface
    ?
    j
    t
    • 3
    • 5
  • a

    andrewreitz

    11/13/2020, 4:37 PM
    Hi all, anyone have experience setting a proxy on the node/yarn exec that gradle uses in a kotlin-js project? Googling doesn’t produce any results and I don’t see notice anything on the KotlinJsNodeDsl class.
    b
    t
    j
    • 4
    • 19
  • m

    Mauily

    11/13/2020, 6:45 PM
    Hi all, I've just create a new fullstack project from the template Intellij provides (when you start a new project). This all behaves wonderfully, I added serialization to the backend no problem, but now I've come to add content negotiation and serialization to the front end I've fallen over. I've made this example project of where I'm at: https://github.com/MrBergin/mpp-serialization. Running the provided "run" gradle task builds my JS, starts up my server, but when I visit localhost:8080 I'm hit with "Uncaught TypeError: Cannot read property 'Json_x26noe$' of undefined". I'd like to try and understand and sort this myself and I'm not by no means asking someone to solve the problem for me, so if someone could point me in the right direction for investigation it'd be much appreciated :)
    r
    • 2
    • 2
  • d

    Daan

    11/13/2020, 11:01 PM
    Is there an easy way to make lightweight add-hoc JS objects with KJS? Lots of js libraries want objects as arguments to mimic optional arguments, so you'd call a function like this:
    libraryFunction({ optionalArg1: 'value', optionalArg2: true });
    So far, I've been using this utility function:
    fun <T> obj(block: T.() -> Unit): T =
        js("{}").unsafeCast<T>().apply(block)
    Which can be used like this:
    libraryFunction(obj { optionalArg1 = "value"; optionalArg2 = true })
    Given the following external declarations:
    external interface Args {
        optionalArg1: String
        optionalArg2: Boolean
    }
    
    external fun libraryFunction(args: Args)
    v
    m
    +2
    • 5
    • 29
  • a

    Axel-F B

    11/14/2020, 12:50 PM
    Hey, im pretty new to Gradle and KotlinJS. I want to inspect the tasks configured in the kotlinjs plugin - is there any way to do that?
    m
    • 2
    • 6
  • a

    andrewreitz

    11/14/2020, 6:54 PM
    Hi, what’s the correct way to export my release version of a kotlin-js project for node, such that I don’t have to run everything through gradle.
    e
    b
    • 3
    • 5
Powered by Linen
Title
a

andrewreitz

11/14/2020, 6:54 PM
Hi, what’s the correct way to export my release version of a kotlin-js project for node, such that I don’t have to run everything through gradle.
and or how do I pass command line arguments to node run command?
e

ESchouten

11/14/2020, 7:44 PM
I've seen this plugin being mentioned: https://gitlab.com/lt.petuska/npm-publish
a

andrewreitz

11/14/2020, 8:07 PM
Thanks, I’m not trying to publish the code, i just want to run the script without having to go through gradle
or at the bare minimum be able to pass command line args to my program, but I’m not really sure how to do that with gadle being in contrrol of npm
b

Big Chungus

11/16/2020, 8:47 AM
You can use npm-publish to assemble your node module. From there you can run npm commands as you wish
View count: 2