Questions tagged [kotlin-js]

281 questions
6
votes
2 answers

Load resource file (json) in kotlin js

Given this code, where should I place the file.json to be able to be found in the runtime? // path: src/main/kotlin/Server.kt fun main() { val serviceAccount = require("file.json") } I tried place it under src/main/resources/ without luck. I also…
Diolor
  • 13,181
  • 30
  • 111
  • 179
6
votes
3 answers

Gradle doesn't emit kotlin.js

I'm trying to compile my Kotlin app and set of Kotlin libraries to JavaScript. I've got that working well, but when I try to run it it can't find kotlin.js. So what's going on here? When I compile using IDEA (instead of Gradle), it outputs kotlin.js…
Ky -
  • 30,724
  • 51
  • 192
  • 308
5
votes
0 answers

Unable to download nodejs from kotlin multiplatform gradle project

I have built a kotlin multiplatform project using gradle from my home machine without any problems. However upon entering a corporate proxy that does not allow the downloading of executable files. I keep getting the following... **Execution failed…
5
votes
3 answers

How to add tailwindcss to KotlinJS

I am unable to add the tailwindcss library to my KotlinJS project. I tried multiple things. I have multiple dependencies defined in my build.gradle.kts implementation(npm("postcss", "latest")) implementation(npm("postcss-loader",…
5
votes
1 answer

Import external css in a Kotlin React app

I want to use css library like bootstrap/material inside my Kotlin-React app. Is there a way to import those external css libraries? There is a Kotlin-Styled wrapper but not sure how to use it to import css.
Prabhakar
  • 402
  • 6
  • 20
4
votes
2 answers

When using kotlinx.html's DSL to create HTML, (how) is it possible to refer to the created elements?

I'm writing a browser app in Kotlin/JS, and I'm using kotlinx.html's DSL to generate some of the HTML. For (a simple) example: (window.document.body!! as Node).append { p { +"Some text" } p { +"Click here" …
Tom
  • 4,910
  • 5
  • 33
  • 48
4
votes
0 answers

kotlin/js cant run develpment run

i can't run a freshly created kotlin react project when i try to i get see below error en cant use it > Task :kotlinNpmInstall warning workspace-aggregator-c22f0aa7-62f6-4cd1-b73e-254168ec2f14 > untitled1 > webpack-dev-server > sockjs >…
4
votes
1 answer

How do I add a JS target to a KMM project?

I have an AndrodiStudio KMM project and I'd like to add a JS target. Given that JS development is only available in IntelliJ, I'd expect that I have to open the project in IDEA add a "Module" -- but I don't even know which one to choose -- none of…
4
votes
2 answers

Unit testing in Kotlin JS

I have a simple project in Kotlin JavaScript using React. I've added unit tests, but when I run them, they seem to call main method of production code, and fail on initialization, when trying to reach unexsistent DOM structure. Despite the fact that…
Arsen
  • 664
  • 1
  • 11
  • 29
4
votes
1 answer

dceTask keep is not preserving defined classes

I am building a Kotlin/JS project that will be used as a library for a web app. The kotlin plugin recently enabled DCE and provides a keep directive, but it is not keeping the class I am specifying. kotlin.target.browser { dceTask { keep…
dazza5000
  • 7,075
  • 9
  • 44
  • 89
4
votes
1 answer

How to use a Javascript artifact created by kotlin multiplatform

I'm currentyl creating a kotlin mutliplatform project for jvm and js. My build.gradle.kts looks like this: plugins { id ("org.jetbrains.kotlin.multiplatform") } repositories { mavenCentral() } kotlin { jvm() { …
Florian
  • 51
  • 2
4
votes
3 answers

How do I call JS functions like setTimeout in Kotlin when not targeting browsers

Do I have to define them externally like so: external fun setTimeout(exec: suspend () -> Unit, timout: Int) Or is there something in the stdlib I can use? I can't use kotlin.browser.window.setTimeout because I want to run it with nodejs.
thi gg
  • 1,969
  • 2
  • 22
  • 47
4
votes
1 answer

Kotlin 1.3.20 with Gradle 5.1.1 compileKotlin2Js execute hot reload

In Kotlin 1.3.20 and Gradle 4.10.2, it is possible to hot reload js files with the following in Gradle: task watch { inputs.files 'src/main' doLast { compileKotlin2Js.execute() } } However, then we get a warning of: Deprecated…
AlexO
  • 1,311
  • 12
  • 18
4
votes
1 answer

Using runBlocking in Kotlin Coroutines when targeting JavaScript?

Is there a way to write the Kotlin code below so that it compiles and works the same way on the JVM and in JavaScript? fun request(request: Any): A = runBlocking { suspendCoroutine { cont -> val subscriber = { response: A…
auser
  • 6,307
  • 13
  • 41
  • 63
4
votes
2 answers

Gradle gets dependency but doesn't use it on build

I am working on a web app in Kotlin/JS, and I'm trying to use a Kotlin library "com.beust:klaxon:3.0.1" (I've explicitly compiled the lib's dependencies and removed them from the lib to reduce probability of version conflict, after not succeeding…
EmmanuelMess
  • 1,025
  • 2
  • 17
  • 31
1
2
3
18 19