不能要求Electron中的渲染器自定义模块

我正在尝试制作一些可以在我的项目中使用的类,但是我在导入正在导入的模块时遇到了一些麻烦。

我的文件结构如下所示:

├╴main.js └╴src/ ├╴html/ │ └╴index.html ├╴css/ │ └╴index.css └╴js/ ├╴index.js └╴participant.js 

所有的index.*文件是相互关联的,因此具有相同的名称。

讨论的问题是index.jsindex.html呈现器和participant.js

这是我得到的代码:

 // index.js const {Participant} = require("./participant"); const addNodeBtn = document.getElementById('add-node'); addNodeBtn.addEventListener('click', () => { // this is really just filler code to see if everything works let p = new Participant("Jason"); alert(`His name was ${p.name}`); }); 

 // participant.js "use strict"; var Participant = class { constructor(name) { this.name = name; } } module.exports.Participant = Participant; 

不pipe出于什么原因,我总是收到错误“找不到模块./participant”。

以下是我尝试过的select:

 require("participant"); require("./participant.js"); module.exports = Participant; module.exports.Participant = class { ... } 

都无济于事,都给我同样的错误。 我甚至把index.js改名为其他东西,认为它与require机制相冲突。 仍然没有改变。

任何帮助解决这个问题?

更新这似乎是从我的main.js文件中工作。