I’m trying to use the `uuid` npm package but I ge...
# javascript
j
I’m trying to use the
uuid
npm package but I get the error
TypeError: v4 is not a function
This is my code :
Copy code
@JsModule("uuid")
@JsNonModule
@JsName("v4")
external fun jsUuid(): String

actual fun uuid() = Id(v4())
This is the npm doc
Copy code
import { v4 as uuidv4 } from 'uuid';
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
What should I change to make it work? I did read this https://kotlinlang.slack.com/archives/C0B8L3U69/p1646004687047799 but didn’t get it to work still.
t
Copy code
@file:JsModule("uuid")
@file:JsNonModule

@JsName("v4")
external fun uuidv4(): String
👍🏻 1
j
It worked, thanks. I did try something similar yesterday night bit I was probably too tired to see what was wrong
a
There is a great uuid MPP package btw https://github.com/benasher44/uuid
👍 1