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

    PHondogo

    05/12/2020, 8:24 AM
    Hello! I'm trying to compile Kotlin into js using new Ir backend and 1.4-M1 version of Kotlin. But got compilation error:
    Caused by: java.lang.AssertionError: Built-in class kotlin.Any is not found
    My configuration: in gradle.properties:
    kotlin.js.compiler=ir
    In gradle.build
    kotlin { 
      target { 
        useCommonJs()
        produceExecutable()
        browser {}
      }
    }
    i
    • 2
    • 4
  • c

    Chilli

    05/12/2020, 9:31 AM
    Can we check in runtime whether the program is running on node.js or frontend JS?
    a
    g
    • 3
    • 7
  • p

    PHondogo

    05/12/2020, 7:32 PM
    Hello! How to add class/object static initializer in js generated code to be able to execute on js start without explicitly calling from main
    object Test {
      init { // want to execute it on js start without calling Test from main method
        window.alert("test")
      } 
    }
    q
    t
    • 3
    • 5
  • y

    yogi

    05/13/2020, 9:47 AM
    Hello, not sure if this belongs to js or #multiplatform , but will go ahead and ask here So the basic problem I'm trying to solve is to mimic the behaviour of having multiple modules for a target such that each individual 'module' can be built independently - having it's own tests and sources - so that one is working within that particular modules, one runs the test cases only for that module (thus, getting faster iteration cycles) Now, in multiplatform analogy, I believe this would translate to a
    sourceSet
    . I have configured a
    custom sourceSet
    as below
    js {
            browser {}
            nodejs {
                useCommonJs()
            }
    
            val fooMain  by compilations.creating {
                nodejs {
                    useCommonJs()
                }
                defaultSourceSet {
                    dependencies {
                        api(kotlin("stdlib-js"))
                        implementation(npm("<some-dependency>","some-version"))
                    }
                }
            }
    
            val fooTest by compilations.creating {
                defaultSourceSet {
                    dependsOn(fooMain.defaultSourceSet)
                    dependencies {
                        implementation(kotlin("test-js"))
                    }
                }
            }
    
        }
      // Some other config 
      sourceSets {
            val jsMain by getting {
                dependsOn(getByName("fooMain"))
                // some more config
            }
      }
    Now, the question is - How do I write a task that 'compiles and runs' the tests written in
    fooTest
    . The [documentation](https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#running-tests) mentions that
    For Kotlin/JS targets, add kotlin-test-js as a test dependency. At this point, test tasks for Kotlin/JS are created but do not run tests by default; they should be manually configured to run the tests with a JavaScript test framework.
    Now, I believe that means configuring a
    KotlinJsTest
    task that has
    useMocha()
    configured. However, I am unable to wire up such a task. Can someone please help me out? Also, apologies if this is present somewhere in the documentation - if it is, please direct me to it. If it isn't , please direct me how I can add it once I have the answer 🙂
    d
    • 2
    • 3
  • r

    Robert Jaros

    05/13/2020, 12:21 PM
    Is DCE somehow built-in into the compiler in 1.4?
    b
    s
    • 3
    • 6
  • o

    Omar Mainegra

    05/13/2020, 3:09 PM
    Hi everyone, is there a way to set Mocha timeout? The
    timeout
    parameter only works in node, not in browser
    t
    s
    • 3
    • 23
  • m

    Marian Schubert

    05/13/2020, 3:36 PM
    I have pure kotlin-js project, but I have some code which isn't JS specific (e.g., some state management) and I would like to run it's tests using JVM (so that they are faster to run). How should I configure such project? Would appreciate any hints.
    s
    • 2
    • 13
  • r

    Robert Jaros

    05/13/2020, 4:15 PM
    What is the difference between
    produceExecutable()
    and
    produceKotlinLibrary()
    in Kotlin 1.4-M1 Gradle DSL?
    s
    g
    • 3
    • 7
  • p

    PHondogo

    05/13/2020, 9:07 PM
    how to disable DCE for some properties/functions?
    t
    d
    • 3
    • 4
  • f

    Franco

    05/14/2020, 1:05 AM
    Hi everyone, seems like the
    JsObject
    class is no longer available in the latest versions of the
    kotlinext
    in
    kotlin-wrappers
    , was it renamed or replaced by other class or just removed? @turansky I know you've made a lot of changes to that repo so you might know
    t
    • 2
    • 2
  • a

    ankushg

    05/15/2020, 2:16 AM
    Anyone using 1.4-M1 have ideas on how to resolve a
    e: java.lang.ClassCastException: org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl cannot be cast to org.jetbrains.kotlin.ir.expressions.IrExpressionWithCopy
    ?
    t
    i
    • 3
    • 9
  • k

    Knut

    05/16/2020, 10:37 AM
    Hi guys 👋 I'm having trouble with the new typescript definition export from Kotlin in 1.4-M1 😓 (1) Adding @ JsExport outside jsMain source directory in multiplatform Gradle project does not work*? So this means that one cannot export type definitions for types that are shared between platform targets? (2) When creating a regular kotlin/js project in IntelliJ, I cannot find a way to activate the new IR back-end compiler and the definition export - I assume this is not supported? Typescript definition export would simplify my current project dramatically, so I keep hoping it would be possible to get at least one of these options working? 🤞 Edit : the IR backend is activated in the gradle.properties file.
    t
    b
    • 3
    • 6
  • d

    dpux

    05/17/2020, 8:04 PM
    Hi everyone! I am new to Kotlin/JS and wanted to explore the framework by writing helper functions (no UI) in Kotlin that could be reused in a separate react JS project. The community seems to have trouble publishing Kotlin libraries as an npm package, So I thought of putting the output of ‘browserDevelopmentWebpack’ in the src/ of React project. Still unable to load the kotlin library using require or ES6 imports. Is there a library target that I should specify for my usecase? Any samples would be appreciated. I am using Kotlin 1.3.72.
    s
    a
    • 3
    • 23
  • r

    Rachid

    05/17/2020, 8:46 PM
    Hi, I just started a multiplatform project where "domain" is the common Kotlin code, and I created another Gradle subproject for JS. But the build fails with:
    project ':domain' is not configured for JS usage
    Any idea what is wrong? For the JVM subproject I already got it working
    t
    • 2
    • 4
  • p

    PHondogo

    05/18/2020, 1:09 PM
    Hello! Is there prerelease version of kotlinx.html for kotlin-1.4-M1?
    s
    • 2
    • 2
  • u

    Ugi

    05/18/2020, 5:44 PM
    A couple of question regarding
    js("...")
    code block. In pre 1.4 I had this code to determine if I'm running on node or in browser (it's inside an actual implementation of expected method in multi platform project)
    val runningOnNode = js(
                "if (typeof window === 'undefined') {\n" +
                        "             true;\n" +
                        "    } else {\n" +
                        "            false;\n" +
                        "    }"
            )
    Since switching to 1.4 and enabling IR, that block started returning
    undefined
    where it was previously a boolean true or false. I worked around this with this:
    val runningOnNode = js(
                "var isNode = false;\n" +
                        "if (typeof window === 'undefined') {\n" +
                        "             isNode = true;\n" +
                        "    } else {\n" +
                        "            isNode = false;\n" +
                        "    }\n" +
                        "return isNode;"
            )
    So I have two questions, and please consider that my JS knowledge is very limited: 1. Is this expected change that came with 1.4 or is it a bug? 2. Am I using
    js(...)
    code block in a way that it was not meant to be used, and causing the issue myself?
    t
    g
    • 3
    • 4
  • n

    Nicholas Bilyk

    05/18/2020, 7:27 PM
    I'm trying out the new IR JS kotlin compiler. I love it so far, but I'm hitting a big problem. If I try to recompile I get the following error:
    > Task :compileKotlinJs FAILED
    
    Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
    Use '--warning-mode all' to show the individual deprecation warnings.
    See <https://docs.gradle.org/6.1/userguide/command_line_interface.html#sec:command_line_warnings>
    5 actionable tasks: 1 executed, 4 up-to-date
    e: java.nio.file.FileSystemException: ...\build\classes\kotlin\main\default\ir\bodies.knb: The process cannot access the file because it is being used by another process.
    
    	at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
    	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
    	at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
    	at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:274)
    	at java.base/sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:105)
    If I force stop the openjdk platform binary process, it works again.
    b
    • 2
    • 5
  • m

    mkosm

    05/19/2020, 8:20 AM
    I'm trying to update the libs I'm using to ones that support 1.4-M1 in order to try the new IR compiler, but I'm getting errors like
    Could not resolve org.jetbrains:kotlin-react:16.13.0-pre.95-kotlin-1.4-M1
    for all of my libs, even though I have included the required maven repositories. The lib exists on the maven server: https://kotlin.bintray.com/kotlin-js-wrappers/org/jetbrains/kotlin-react/16.13.0-pre.95-kotlin-1.4-M1/ I'm including my full
    build.gradle.kts
    file. What am I doing wrong?
    Untitled
    t
    i
    • 3
    • 14
  • m

    Mranders

    05/19/2020, 2:46 PM
    We are in the process of moving away from the frontend plugin to the new JS plugin. Everything works fine for a while, but then compiles in IntelliJ starts failing with the stacktrace below. The error and the warnings about invalid Kotlin Javascript libraries goes away for a while if the .idea folder is deleted and IntelliJ restarted. However, after some time it reappears. Has anyone had a similar problem, and know of a way to solve it?
    Information:kotlin: kotlinc-js 1.4-M1 (JRE 1.8.0_232-b09)
    Information:19/05/2020 16.15 - Build completed with 1 error and 28 warnings in 10 s 86 ms
    Error:kotlin: [Internal Error] java.io.IOException: Failed to open zip file: C:\Work\hltv\build\js\node_modules\jquery\dist\jquery.js
    at org.jetbrains.kotlin.utils.JsLibraryUtils.traverseArchive(JsLibraryUtils.kt:118)
    at org.jetbrains.kotlin.utils.JsLibraryUtils.copyJsFilesFromZip(JsLibraryUtils.kt:102)
    at org.jetbrains.kotlin.utils.JsLibraryUtils.copyJsFilesFromLibraries(JsLibraryUtils.kt:43)
    at org.jetbrains.kotlin.jps.targets.KotlinJsModuleBuildTarget.copyJsLibraryFilesIfNeeded(KotlinJsModuleBuildTarget.kt:127)
    at org.jetbrains.kotlin.jps.targets.KotlinJsModuleBuildTarget.doAfterBuild(KotlinJsModuleBuildTarget.kt:121)
    at org.jetbrains.kotlin.jps.build.KotlinBuilder.doBuild(KotlinBuilder.kt:457)
    at org.jetbrains.kotlin.jps.build.KotlinBuilder.build(KotlinBuilder.kt:309)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1414)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1092)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1159)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:1053)
    at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:882)
    at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:449)
    at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:190)
    at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:138)
    at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:297)
    at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:130)
    at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:218)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
    Caused by: java.util.zip.ZipException: error in opening zip file
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:225)
    at java.util.zip.ZipFile.<init>(ZipFile.java:155)
    at java.util.zip.ZipFile.<init>(ZipFile.java:126)
    at org.jetbrains.kotlin.utils.JsLibraryUtils.traverseArchive(JsLibraryUtils.kt:116)
    ... 20 more
    Warning:kotlin: 'C:/Work/hltv/build/js/node_modules/jquery/dist/jquery.js' is not a valid Kotlin Javascript library
    Warning:kotlin: 'C:/Work/hltv/build/js/node_modules/moment-timezone/index.js' is not a valid Kotlin Javascript library
    Warning:kotlin: 'C:/Work/hltv/build/js/node_modules/moment/moment.js' is not a valid Kotlin Javascript library
    Warning:kotlin: 'C:/Work/hltv/build/js/node_modules/react-sortable-hoc/dist/react-sortable-hoc.js' is not a valid Kotlin Javascript library
    Warning:kotlin: 'C:/Work/hltv/build/js/node_modules/regenerator-runtime/runtime.js' is not a valid Kotlin Javascript library
    i
    a
    • 3
    • 6
  • m

    Martin Gagnon

    05/20/2020, 2:10 PM
    We are migrating one of our mobile codebase (already in production) to kotlin 1.4M to support Typescript and provide a JS implementation. However we have some issues regarding the new IR backend and @JSExport. Here are some questions: Is there a way for @JsExport to export transitive dependencies ? The following code produce an error:
    @JsExport
    data class A(val b: String) {
        companion object
    }
    e: java.lang.AssertionError: Properties without fields are not supported A.Companion_instance
    Also, when using the 
    @JsExport
     annotation on an 
    object
    , example:
    @JsExport
    object A {
      var b: String = ""
    }
    The following TypeScript definition is generated:
    /* ErrorDeclaration: Class A with kind: OBJECT */
    Is there any workaround for this? Is there any plan to support those types?
    👀 3
    a
    s
    +2
    • 5
    • 6
  • a

    Andrey Logoshko

    05/20/2020, 7:03 PM
    Hey guys, I'm trying to configure kotlin-multiplatform so that it uses similar configuration as CRKA. So far I've found out that kotlin-gradle-plugin will extend webpack configuration with whatever it finds in root/webpack.config.d folder. The same story with Karma, if you create karma.config.d folder gradle pluging will enhance existing preset configuration with whatever it finds there. Is there any way to enhance package.jason? I'd like to add 'browserslist' there.
    t
    • 2
    • 5
  • g

    Grantas33

    05/20/2020, 8:27 PM
    Is there a way to cast Job to Promise, since some JS functions require returning/passing a Promise?
    r
    • 2
    • 3
  • f

    Franco

    05/20/2020, 9:25 PM
    Hi everyone, I'm having an issue trying to update a text field value using the React Wrapper, what I want to do works on JS but I can't make it work on Kotlin/JS, if anyone can give me a hand it'd be greatly appreciated as I've been hitting a wall for several hours 😕 The details of the problem are on this issue: https://github.com/JetBrains/kotlin-wrappers/issues/298
    c
    i
    t
    • 4
    • 45
  • j

    Joffrey

    05/21/2020, 9:47 AM
    Hi guys, is there a built-in way to access whether I’m in production or dev from Kotlin/JS code running in the browser?
    g
    v
    • 3
    • 15
  • t

    Tristan

    05/22/2020, 12:36 AM
    Hello, Using the latest version of Kotlin-Wrapper for React, I am trying to use
    useContext
    but I am facing this error
    When accessing module declarations from UMD, they must be marked by both @JsModule and @JsNonModule
    Have you already encountered this issue?
    t
    i
    • 3
    • 4
  • n

    Nicholas Bilyk

    05/22/2020, 3:21 AM
    Trying out kotlinx.html -- How does one unit test things that use this? Both with browser test (mocha) and nodejs test with jsdom I get:
    ReferenceError: HTMLLegendElement is not defined
        at D:\Projects\acornui2\build\js\packages_imported\kotlinx-html-js\0.7.1\kotlinx-html-js.js:66:29
    Also, is there a version that uses es5?
    d
    • 2
    • 2
  • f

    frank

    05/23/2020, 1:27 AM
    I'm developing a Project with Node and it is failing build with Gradle when i configure with JDK more higher than 10. Dont show any error but not generate outputFile and other gradle tasks fail. Any limits on the version of the JDK in Kotlin/JS or node?
    plugins {
            id("org.jetbrains.kotlin.js") version "1.4-M1"
    }
    
    repositories {
        maven("<https://dl.bintray.com/kotlin/kotlin-eap>")
        jcenter()
        mavenCentral()
    }
    
    dependencies {
        implementation(kotlin("stdlib-js"))
    }
    
    kotlin.target {
        useCommonJs()
        nodejs()
    }
    tasks.compileKotlinJs {
            kotlinOptions.outputFile = "routes/node/index2.js"
            kotlinOptions.metaInfo = false
    }
    My Enviroment: - Gradle: 6.4.1 (compatible with JDK 14) - IDEA last eap. (With previus versions the same) - Kotlin 1.4-M1(I tried with old versions)
    i
    v
    • 3
    • 7
  • a

    Ananiya

    05/24/2020, 12:59 PM
    Hi, i am getting this issues
    An exception occurred applying plugin request [id: 'java']
    > Failed to apply plugin [id 'org.gradle.java']
    > Cannot add task 'processResources' as a task with that name already exists.
    while i am creating new kotlin/js project . I am using intellij idea ultimate 2020.1 with jdk 8 and here is my gradle file
    r
    • 2
    • 3
  • g

    Grantas33

    05/24/2020, 7:29 PM
    useCommonJs() is marked as an unresolved reference when I try to use it to compile js in kotlin multiplatform 1.4-M1.
    js {
        useCommonJs()
        produceExecutable()
        browser {}
    }
    Is there a way to compile typescript declarations in commonJs format in kotlin multiplatform 1.4-M1?
    d
    j
    • 3
    • 11
  • a

    Andrew

    05/24/2020, 8:28 PM
    I am just trying to do a simple proof of concept to create a javascript library from a kotlin MP project. Creating a new MP project and building produces a build/distributions/MyProject.js file, I copy and include this in an html <script> and able to do console.log(MyProject) but not sure if its working or how to use it beyond that. I tried the things suggested like "@JsName" or including the package name. For example the default project it creates has a class "Sample" and object "Platform" with package "sample". In Javascript things like MyProject.sample or .Sample or .Platform are all undefined. Inspecting the object does not appear to have anything I recognize either. Using MP 1.3.72 if that matters.
    d
    • 2
    • 3
Powered by Linen
Title
a

Andrew

05/24/2020, 8:28 PM
I am just trying to do a simple proof of concept to create a javascript library from a kotlin MP project. Creating a new MP project and building produces a build/distributions/MyProject.js file, I copy and include this in an html <script> and able to do console.log(MyProject) but not sure if its working or how to use it beyond that. I tried the things suggested like "@JsName" or including the package name. For example the default project it creates has a class "Sample" and object "Platform" with package "sample". In Javascript things like MyProject.sample or .Sample or .Platform are all undefined. Inspecting the object does not appear to have anything I recognize either. Using MP 1.3.72 if that matters.
I tried this on another project that did something with the document in main() which worked. It looks like the javascript is only generated for code that's used. Since this is for a library I don't need main() and most of the code is classes/functions that are never called except outside the project. Is there a setting to fix this?
Setting the dcetask in build.gradle might be a fix for this but seems very unintuitive as a solution for a common setup.
d

Darran

05/28/2020, 4:57 AM
that is the fix I use https://stackoverflow.com/a/60592459/3268303
View count: 4