在JS中安装npm uuid后无法调用uuid函数

ace*_*roo -1 javascript uuid node.js electron

在JS中安装npm uuid后,我无法调用uuid函数,使用电子

这是我安装时终端上的消息,我不知道这是否正确安装

$ npm install uuid
npm WARN pemrograman_visual2@1.0.0 No description
npm WARN pemrograman_visual2@1.0.0 No repository field.

+ uuid@7.0.3
updated 1 package and audited 120 packages in 1.746s

2 packages are looking for funding
  run `npm fund` for details

found 1 low severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details
Run Code Online (Sandbox Code Playgroud)

这是我调用函数的地方

ipcMain.on("appointment:create", (event, appointment) => {
    appointment["id"] = uuid();
    appointment["done"] = 0;
    allAppointment.push(appointment);

    CreateWindow.close();

    console.log(allAppointment);
});
Run Code Online (Sandbox Code Playgroud)

但是当我使用 $npm start 运行程序时,它说 TypeError: uuid is not a function

Mel*_*hia 9

文档中您可以导入 uuid:

使用导入/导出语法:

import { v4 as uuid } from 'uuid';
uuid();
Run Code Online (Sandbox Code Playgroud)

使用 commonJs 语法:

const uuid = require('uuid').v4;
uuid();
Run Code Online (Sandbox Code Playgroud)