Hello :wave: Beginner question : What should I do ...
# javascript
d
Hello 👋 Beginner question : What should I do to get the @JsModule Annotation to work. I have applied the kotlin multi-platform plugin and configured
kotlin { js(IR) { nodejs() } }
. Currently IDE(IDEA) says unresolved reference.
r
What are you trying to do?
d
I want to use a node module in my kotlin code.
something like this
Copy code
@JsModule("my-module")
external fun myModule(): String
r
Check out https://kotlinlang.org/docs/using-packages-from-npm.html as a starting point. It's pretty concise documentation so read carefully 🙂 Here is an example for Sortable.js - but be warned, there's a lot of variation in how you approach this based on the library.
Copy code
@file:JsModule("sortablejs")
@file:JsNonModule
package rcp.libs

import org.w3c.dom.Element

@JsName("default")
external object Sortable {
    fun create(el: Element, options: SortableOptions)
}
One thing that can be useful: after running gradle to import it, look in build/js/node_modules at the structure of the library you're working with.