在Node.js erros中生成UUID V5,没有任何信息?

发布于 2025-02-12 06:10:39 字数 2063 浏览 0 评论 0原文

我正在使用此NPM软件包:

https://wwwww.npmjs.coms.com/package/package/package/package/uuid

我想赋予V5 UUID。

我可以通过需要模块来生成V4没有问题:

const { v4: uuidv4 } = require('uuid');

然后运行:

console.log(`uuidv4: ${uuidv4()}`);

因此,我尝试生成一个v5:

const { v5: uuidV5 } = require('uuid');
const MY_NAMESPACE = 'f709b20b-3353-4c32-8df9-66bc48e91ea9';
var v5uuid = uuidV5('hello', MY_NAMESPACE);
console.log(`userUUID: ${v5uuid}`);

但是,该应用程序可以行var v5uuid = uuidv5('Hello'hello',my_namespace); 然后直接遇到捕获错误。在变量错误中说:

'uuidv5不是函数'

运行npm ls uuid

├─┬ [email protected]
│ └─┬ [email protected]
│   └─┬ [email protected]
│     └── [email protected]
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected]
└── [email protected]

我在做什么错?

I am using this npm package:

https://www.npmjs.com/package/uuid

I want to egenrate a v5 uuid.

I can generate a v4 no problem by requiring the module:

const { v4: uuidv4 } = require('uuid');

and then running:

console.log(`uuidv4: ${uuidv4()}`);

So then I try to generate a v5:

const { v5: uuidV5 } = require('uuid');
const MY_NAMESPACE = 'f709b20b-3353-4c32-8df9-66bc48e91ea9';
var v5uuid = uuidV5('hello', MY_NAMESPACE);
console.log(`userUUID: ${v5uuid}`);

However, the app gets to line var v5uuid = uuidV5('hello', MY_NAMESPACE); and then goes straight to the catch error. In the variables error says:

'uuidV5 is not a function'

running npm ls uuid:

├─┬ [email protected]
│ └─┬ [email protected]
│   └─┬ [email protected]
│     └── [email protected]
├─┬ [email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected]
└── [email protected]

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城挽邺 2025-02-19 06:10:40

下面的解决方案对我有用!

如果您使用package.json,请添加以下

{
 "type": "module"
 ...
}

// index.js
import { v5 as uuidv5 } from "uuid";

const MY_NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341";

uuidv5("Hello World", MY_NAMESPACE); // ⇨ 'a572fa0f-9bfa-5103-9882-16394770ad11'

内容
节点索引

Below solution worked for me!

If your using package.json, add the following to package.json

{
 "type": "module"
 ...
}

Now use can use import with node js

// index.js
import { v5 as uuidv5 } from "uuid";

const MY_NAMESPACE = "1b671a64-40d5-491e-99b0-da01ff1f3341";

uuidv5("Hello World", MY_NAMESPACE); // ⇨ 'a572fa0f-9bfa-5103-9882-16394770ad11'

Check your output using
node index.js

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文