Questions tagged [kotlin-js]

155 questions
16
votes
6 answers

javascript anonymous object in kotlin

how to create JavaScript anonymous object in kotlin? i want to create exactly this object to be passed to nodejs app var header = {“content-type”:”text/plain” , “content-length” : 50 ...}
John Abraham
  • 163
  • 1
  • 4
10
votes
1 answer

How is Kotlin specifically compiled?

I'm trying to understand the journey Kotlin source code goes through when it is compiled. The documentation states When targeting the JVM, Kotlin produces Java compatible bytecode. When targeting JavaScript, Kotlin transpiles to ES5.1 and generates…
9
votes
2 answers

How to compile Kotlin into TypeScript?

I have a JavaScript build in my Kotlin project. How can I produce full TypeScript code instead of JavaScript? I use Maven; but if you have a Gradle solution, I'm interested.
sab
  • 2,521
  • 3
  • 24
  • 46
8
votes
1 answer

How to unit-test Kotlin-JS code with coroutines?

I've created a multi-platform Kotlin project (JVM & JS), declared an expected class and implemented it: // Common module: expect class Request(/* ... */) { suspend fun loadText(): String } // JS implementation: actual class Request actual…
egor.zhdan
  • 4,185
  • 5
  • 38
  • 50
6
votes
2 answers

Why Does Kotlin/JS Return Different Results for === Than Does Kotlin/JVM?

Given this code: val value = "something" println(value.toUpperCase().toLowerCase() == value) // prints true println(value.toUpperCase().toLowerCase() === value) // prints false On Kotlin/JVM 1.3.40, I get: true false On Kotlin/JS 1.3.40, I…
CommonsWare
  • 910,778
  • 176
  • 2,215
  • 2,253
6
votes
3 answers

How to define a global js function in Kotlin?

Every function and variable that I create in KotlinJs project gets into a module. But I need to define some functions in global scope. I use p5js library (pure js). It allows user to define event handling functions in global scope. I'm trying to use…
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…
Ben Leggiero
  • 25,904
  • 38
  • 161
  • 267
5
votes
1 answer

Instantiate Javascript classes that expect "new" keyword on KotlinJS

considering the following javascript code (partially taken from Apollo Server documentation), it creates an instance of ApolloServer and start it. const {ApolloServer} = require('apollo-server') const server = new ApolloServer({ ...…
Jac
  • 610
  • 3
  • 13
5
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
  • 12,142
  • 23
  • 103
  • 165
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
  • 392
  • 4
  • 20
4
votes
1 answer

How to apply -Xopt-in=kotlin.ExperimentalUnsignedTypes to all subprojects?

I have a project with multiple subprojects that use the kotlin-multiplatform plugin or the kotlin-js plugin and I want to use the experimental unsigned types in all of them. So far I've tried this, which doesn't work: subprojects { …
Daan
  • 1,356
  • 10
  • 17
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
  • 166
  • 1
  • 10
  • 26
3
votes
1 answer

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",…
3
votes
2 answers

How to import react-bootstrap component with children into kotlin-js react app

I want to use a bootstrap Card component in a react website created with kotlin-js. The app uses kotlin-react wrapper and react-bootstrap library. react-bootstrap documentation says use to put content. This is some…
3
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
  • 542
  • 1
  • 9
  • 26
1
2 3
10 11