【问题标题】:can't call uuid function after install npm uuid in JS在 JS 中安装 npm uuid 后无法调用 uuid 函数
【发布时间】:2020-04-03 10:16:04
【问题描述】:

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

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

$ 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

这是我调用函数的地方

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

    CreateWindow.close();

    console.log(allAppointment);
});

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

【问题讨论】:

  • 你是不是像const uuid = require('uuid').v4;一样导入了?
  • 是的,我像这样导入它const uuid = require("uuid");

标签: javascript node.js electron uuid


【解决方案1】:

the documentation 这就是你导入 uuid 的方式:

使用导入/导出语法:

import { v4 as uuid } from 'uuid';
uuid();

使用 commonJs 语法:

const uuid = require('uuid').v4;
uuid();

【讨论】:

    猜你喜欢
    • 2022-01-21
    • 2019-03-21
    • 2012-10-28
    • 2017-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-27
    • 2020-05-19
    相关资源
    最近更新 更多