https://kotlinlang.org logo
#javascript
Title
# javascript
j

jean

02/04/2023, 10:42 PM
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

turansky

02/04/2023, 10:58 PM
Copy code
@file:JsModule("uuid")
@file:JsNonModule

@JsName("v4")
external fun uuidv4(): String
👍🏻 1
j

jean

02/05/2023, 6:23 AM
It worked, thanks. I did try something similar yesterday night bit I was probably too tired to see what was wrong
a

Arjan van Wieringen

02/05/2023, 9:13 AM
There is a great uuid MPP package btw https://github.com/benasher44/uuid
👍 1
5 Views