Hello everyone. I'm trying to import JS library (j...
# javascript
a
Hello everyone. I'm trying to import JS library (js-cookie) from NPM. Here is code:
Copy code
implementation(npm("js-cookie", "^3.0.5"))
There is no errors with compilation or in runtime, but I can't use functions from this library:
Copy code
package ru.cororo.songpay.util.js

@JsModule("js-cookie")
@JsNonModule
external object Cookies {
    fun set(key: String, value: String)

    fun get(key: String): String?

    fun remove(key: String)
}
I got error while accessing to Cookies.get:
Copy code
TypeError: Cookies.get is not a function
When I printed the
Cookies
object, I got
[object Module]
(JSONified:
{"default": {}}
). I tried to downgrade version to 2.2.1 and... it works!
Cookies.get
now is correct function. I think reason is that 3.0.0 version now provides ES module. How I can fix it? (library: https://github.com/js-cookie/js-cookie/)
Oh yes, version of Kotlin is 2.0.0
e
It looks like
Cookies
is assigned to
global.Cookies
With
global
being
Window
in a browser
Ah wait. You can probably do this
Copy code
@file:JsModule("js-cookie")

package ru.cororo.songpay.util.js

@JsName("default")
external object Cookies {
    fun set(key: String, value: String)
    fun get(key: String): String?
    fun remove(key: String)
}
Should work
❤️ 3
a
It works, thank you very much!