Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: uuid_1.v5 is not a function

Attempting to generate a UUID with the package uuid using these steps:

Installation

npm i -S uuid @types/uuid

Code

    import { v5 } from 'uuid';
    const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
    console.log(v5('Hello, World!', MY_NAMESPACE));

When I run that I get:

    TypeError: uuid_1.v5 is not a function
        at Object.<anonymous> (/home/ole/slice/test.ts:3:13)
        at Module._compile (internal/modules/cjs/loader.js:654:30)

Thoughts?

like image 259
Ole Avatar asked Aug 28 '18 01:08

Ole


2 Answers

DefinitelyTyped is wrong: the uuid module does not export v5. Your import should be:

import v5 = require('uuid/v5');

Or if you have esModuleInterop enabled, you can use:

import v5 from 'uuid/v5';
like image 170
Matt McCutchen Avatar answered Oct 15 '22 18:10

Matt McCutchen


I was also getting the similar problem.

Try the following and it will work.

//I use v4 so , but try .v5 if you want to
const uuid = require('uuid').v4

//now can call uuid
uuid()
like image 35
Badri Paudel Avatar answered Oct 15 '22 17:10

Badri Paudel