an working solution for now is ``` private externa...
# javascript
f
an working solution for now is
Copy code
private external fun require(module: String): MyModule

fun get(): MyModule {
            return require("myModule")
}

external interface MyModule {
    fun myMethod(...)
}
g
Usually you don’t need it, you can use external declaration for MyModule
But if for some reason you need this, you can write universal version of require
external fun <T> require(module: String): T
👍 1
f
Thanks
j
Looks like JS modules can be "imported" via the
@JsModule
annotation on the external resource being defined. e.g.:
Copy code
@JsModule("myModule")
external interface MyModule {
    fun myMethod(...)
}
see https://stackoverflow.com/questions/44192288/kotlin-how-to-import-node-packages and https://kotlinlang.org/docs/reference/js-modules.html#jsmodule-annotation
f
declaring it as an external object worked because it didn't had an constructor