Questions tagged [kotlin-js]
281 questions
18
votes
8 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
- 183
- 1
- 4
15
votes
3 answers
Kotlin/JS, Gradle Plugin : Unable to load '@webpack-cli/serve' command
I was doing the tutorial for React Kotlin and couldnt even finish the setup step because the server does not start.
The code is unchanged : https://github.com/kotlin-hands-on/web-app-react-kotlin-js-gradle
Stacktrace:
[webpack-cli] Unable to load…

Mokyx
- 161
- 4
14
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…

Alessandro Lorusso
- 327
- 2
- 16
13
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
- 4,352
- 7
- 36
- 60
11
votes
3 answers
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,555
- 6
- 39
- 53
10
votes
2 answers
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,516
- 12
- 20
9
votes
2 answers
Is it possible to import a JavaScript file in a Kotlin/JS project?
If I have a JavaScript file called myfile.js as follows:
function myJsFunc() { return "Hello from JavaScript"; }
How can I import this file into a Kotlin/JS project and invoke myJsFunc() from Kotlin code?

funkybro
- 8,432
- 6
- 39
- 52
9
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
- 986,068
- 189
- 2,389
- 2,491
8
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…

Sergey Belonozhko
- 445
- 2
- 9
7
votes
2 answers
How do you add css to a Kotlin JS project?
I created a new Kotlin/JS Gradle project using the wizard in IntelliJ.
I'm unclear how I'm supposed to add css to the project. The documentation explains how to enable css webpack support, but it doesn't actually say how to add the css file into…

vbyzjnlehi
- 307
- 2
- 15
7
votes
1 answer
Can I use coroutines in Kotlin when targeting JavaScript?
Is it possible to launch any coroutines when targeting JavaScript?
It doesn't like any of the usual ways like async{}
Example on: https://github.com/thigg/no-kotlinx-in-js

thi gg
- 1,969
- 2
- 22
- 47
7
votes
1 answer
Kotlin-js: Define number of decimals
Let's imagine something like this:
var num: Float = 0.0f
num = 2.4 * 3.5 / 3.8
num has several decimals, but I want only 2.
In JS I would use num.toFixed(2).
Other answers here suggest to use "%.2f".format(num) or num.format(2). The latter needs a…

eloo
- 301
- 1
- 4
- 8
6
votes
1 answer
How to convert Javascript exported class to Kotlin/JS?
I am new to JS and to Kotlin/JS. I have the following minimal working Javascript code for a Plugin for Obsidian from an example. It works as expected:
var obsidian = require('obsidian');
class SomePlugin extends obsidian.Plugin {
onload() {
…

findusl
- 2,454
- 8
- 32
- 51
6
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({ ...…

Yak O'Poe
- 760
- 4
- 14
6
votes
1 answer
Exception when building a kotlin/js project: error package.json: Name contains illegal characters
Trying to build the a kotlin/js project and getting the following exception:
error package.json: Name contains illegal characters
The project is…

dazza5000
- 7,075
- 9
- 44
- 89