Hey All I have Been Struggling Fo Creating An Exte...
# javascript
s
Hey All I have Been Struggling Fo Creating An External Class for using this : https://github.com/egoroof/browser-id3-writer library in my Kotlin/JS Project But i cant get to create an object of this class as it expects new keyword. Any Help is Appreciated as I couldnt get it to work even after few hours of trying... whenever I try to Instantiate ID3Writer , at runtime it crashes giving error:
ID3Writer is not a constructor
t
Do you use
IR
compiler?
s
Nope , using LEGACY , i figured IR is having Issues with default defination , while researching for finding solution
t
Could you use CommonJS format for Kotlin/JS?
Copy code
kotlin.js {
    useCommonJS()
}
@JsNonModule
can be removed in this case
r
You could try using plain
require
instead of `@JsModule`:
Copy code
val writer: ID3Writer = require("browser-id3-writer").default(buffer)
s
@turansky I added useCommonJs() and tried but got same error and when I tried removing @JsNonModule it throwed that this declartion be coming from JsNonModule for UMD, btw I am compiling Js for Browser . My gradle script snippet is also shown below:
@robstoll I tried your method too and it gave me :
__webpack_require__(...).default is not a function
r
This works fine for me:
Copy code
@JsModule("browser-id3-writer")
@JsNonModule
external class ID3Writer(a: ArrayBuffer) {
    fun getBlob(): Blob
    // ...
}

        val writer = ID3Writer(ArrayBuffer(10))
        val blob = writer.getBlob()
        console.log(blob)
👍 1
s
@robstoll on Legacy Compiler ?
r
on both legacy and ir
btw, I'm not
@robstoll
:-)
s
oopsss.... , let me invalidate cache and restart... I hope it works. Anyway I appreciate your help,Thanks man.
got it working , I dont know wh it didnt worked when I tried same , maybe cache /etc issue....
t
With UMD?
s
yup