Questions tagged [kotlin-js-interop]

62 questions
19
votes
1 answer

No kotlin.js file output by kotlinc-js

Currently trying to get a Kotlin "Hello, World" to compile to JS via the command line. I've followed the tutorial: https://kotlinlang.org/docs/tutorials/javascript/getting-started-command-line/command-line-library-js.html I'm seeing the Javascript…
guyIntrepid
  • 548
  • 5
  • 8
11
votes
4 answers

Kotlin Call Javascript function in Android without webView

Is there any way we can call JS function from Kotlin without having WebView in Android? Let's say as mentioned below I have one JS function helloJS() in test.js file, test.js:- function helloJS(){ return "Hello from JS" } And now I want to call…
Santhi Bharath
  • 2,818
  • 3
  • 28
  • 42
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

What is the right way to import 3rd party React components into the kotlin.js project?

I'm trying to use this lib in my create-react-kotlin-app: https://material-ui-next.com/ I want to generate bunch of type safe wrappers. I started like this: @file:JsModule("material-ui") package material import react.RState import…
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…
7
votes
3 answers

How to execute Kotlin WebAssembly function from JavaScript?

My goal is to write a Kotlin library, compile it to WebAssembly and call its functions from JS. Since a few hours I try to get a simple hello world to work. The documentation on this topic is either non existent or well hidden. This is my kotlin…
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
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
2 answers

How can I set the JsName for a property's backing field in Kotlin?

I played about with Kotlin's unsupported JavaScript backend in 1.0.x and am now trying to migrate my toy project to 1.1.x. It's the barest bones of a single-page web app interfacing with PouchDB. To add data to PouchDB you need JavaScript objects…
HughG
  • 1,108
  • 10
  • 14
5
votes
2 answers

What is simple way to convert dynamically Kotlin/Js objects to plain javascript object?

For example, we have this structure: data class Item( val city: String, val name: String ) val structure = mapOf("items" to listOf( Item("NY", "Bill"), Item("Test", "Test2")) ) And I want to get…
kurt
  • 1,510
  • 2
  • 13
  • 23
4
votes
0 answers

How to call JavaScript (in browser) from Kotlin Native Wasm, passing parameters?

Please excuse me that I don't know if I should ask about all basic types in one post or separately. Main questions: How do I pass an array of floats from Kotlin to JS? How about other "simple" types? Like a float, string? What about other types…
Sunny Pun
  • 726
  • 5
  • 14
4
votes
1 answer

What is the correct way to access the `export default` in KotlinJS

I am playing with Vue and KotlinJS and thought that I can simply get access to the Vue observer functions like Vue.set this way: @JsModule("vue") @JsName("Vue") open external class Vue { companion object { fun set(target: Any, key:…
n_l
  • 844
  • 1
  • 6
  • 19
3
votes
0 answers

Access Javascript file in Kotlin/JS

I have a bunch of Javascript files I need to access from Kotlin Code. I created a js-files directory in my root project with the needed .js files and a package.json which looks like this: { "name": "js-files", "version": "1.0.0", …
Intektor
  • 321
  • 2
  • 13
3
votes
1 answer

Uncaught ReferenceError: firebase is not defined in Kotlin/JS project with Dukat generated declarations

In a basic kotlin js project, I imported the firebase dependency. I used Dukat to get access to the type references and got them to compile. My kotlin compiles like a charm, however it seems to me like the bundle created by webpack does not contain…
jlengrand
  • 12,152
  • 14
  • 57
  • 87
1
2 3 4 5