Questions tagged [kotlin-js]

281 questions
3
votes
1 answer

Kotlin Js - Access Resource Folder

I am starting a project in Kotlin-Multiplatform. Accessing the resource folder via Java is quite easy, but I don't know how to access it via JS targeting Node. During testing, I found out that the resource file is stored in a separate folder. If I'm…
3
votes
3 answers

Kotlin/JS external declaration - "Name contains illegal chars that can't appear in JavaScript identifier"

EDIT: This is not supported yet and tracked on Kotlin YouTrack I'm trying to write a Kotlin external declaration matching the following Typescript interface (this is valid TS to represent JavaScript accesses via headers['content-length']): export…
Joffrey
  • 32,348
  • 6
  • 68
  • 100
3
votes
1 answer

Using pow in KotlinJS in Intellij

There is a library called kotlin.math which contains a method pow: import kotlin.math.pow val factor = pow(10.0, 2) print(factor) and result: 100.0 However Intellij is not registering that I have imported the pow function, is there a special pow…
Robbie Cronin
  • 1,557
  • 2
  • 10
  • 15
3
votes
0 answers

best unit tests for kotlin js application

I am revising a kotlin-js web browser application. Currently tests are run through selenide and are limited as they interact entirely through the DOM and cannot call the code or inspect data. More tests are needed, and I am thinking that an actual…
innov8
  • 2,093
  • 2
  • 24
  • 31
3
votes
2 answers

Kotlin Javascript: Assigning to element property inside event handler gives "Expected a value of type dynamic"

I am using the Kotlin to Javascript transpilation. I have this function to edit a div's contents when a textarea changes. fun doStuff() { val div = document.createElement("div") as HTMLDivElement val textarea =…
Halcyon
  • 1,376
  • 1
  • 15
  • 22
2
votes
0 answers

Is it possible to use in JavaScript interface created in Kotlin.js?

I try to reduce my codebase by using a KMM library compiled for Jvm, Android and Javascript. The simplest code in Kotlin: @JsExport actual interface DataTransferObject { actual val _type: String get() = "temp" } Produces the following code in…
2
votes
1 answer

How to add a react component from an external js library?

I'm trying to add a component from an external library to my react project, but I get an error when I open the page in the browser: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite…
2
votes
1 answer

Using npm dependencies in Kotlin/Js

I need to generate uuid in Kotlin/JS and looking to call uuid.v4() from Kotlin/JS. I have gone through the documentation - https://kotlinlang.org/docs/using-packages-from-npm.html and https://kotlinlang.org/docs/js-modules.html but somehow cannot…
2
votes
1 answer

In a Kotlin multi-platform (or JS) project, (how) can one pass custom command line arguments to Node.js?

I'm working on a Kotlin multi-platform project, and I need my JS tests to run on Node.js but with custom command line arguments (specifically I need node to run with the --expose-gc flag, because some tests need to trigger garbage…
Tom
  • 4,910
  • 5
  • 33
  • 48
2
votes
2 answers

How to import Kotlin/JS generated module in a separate npm-based project

I would like to create a js library with Kotlin Multiplatform (an example of which is this project, where we have a webscocket server and a js client) which I will then build as a npm package and import in my Vue project (could be any other…
2
votes
1 answer

How do I import and use an async JS function in Kotlin/JS?

I'm having issues importing a Javascript async function into my Kotlin code. Here is an example Javascript function : export async function signUp(email, password){ console.log("Signing Up"); try { const userCred = await…
jlengrand
  • 12,152
  • 14
  • 57
  • 87
2
votes
2 answers

Gradle kotlin js module depending on multiplatform module

I have a multiplatform kotlin project for jvm/js. I'd like to extract some common code that's not compile target specific to reuse in both applications. Following is my project structure: ├── api │   ├── build.gradle │   └── src ├── server │   ├──…
Ben
  • 3,989
  • 9
  • 48
  • 84
2
votes
0 answers

Task not found KotlinNpmInstall in KotlinMultiplatform Project targeting JS

after trying to add yarn lock version issue from jetbrains issue tracker I encountered a strange issue. I have a Multiplatform project currently only targeting the web. When I add a line like tasks.named("kotlinNpmInstall").configure { to my web…
Nikola-Milovic
  • 1,393
  • 1
  • 12
  • 35
2
votes
0 answers

How to make RTCPeerConnection be available in Kotlin/JS without declaring the class myself?

I am trying out Kotlin/JS. As an exercice to learn something new I wanted to mess with WebRTC. I've been following the basic examples on their site and at some point you have to instantiate an object from the RTCPeerConnection class. Something very…
Some random IT boy
  • 7,569
  • 2
  • 21
  • 47
2
votes
0 answers

Cannot read properties of undefined (reading 'iterator') in Kotlin Multiplatform

I am trying to run a kmm project js files on a browser. Here the html:
vizsatiz
  • 1,933
  • 1
  • 17
  • 36