我正在使用 Electron 制作应用程序,当我打开开发人员工具时,在控制台中出现此错误:
未捕获的 ReferenceError: 要求未在 index.html:11 中定义
根据某个英语 stackoverflow question,我应该在我的 index.js 中启用 Node 集成,从该电子引导程序:
let win = new BrowserWindow({ width: 2200, height: 1200, title: "Contact Remember", maximizable: true, center: true, frame: true, show: true, webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}});
哪个是属性nodeIntegration: true
。但是这对我不起作用
根据this other question in English,您可以使用以下资源:
Browserify:大多数 Node 模块都可以在浏览器中使用
Webpack:做所有事情(打包 JavaScript 代码、CSS 等)。它因 React 的兴起而流行,但以其陡峭的学习曲线而闻名。
Rollup - 利用 ES6 模块
我不想使用以上 3 个选项中的任何一个,因为我知道不使用它们就会纠正这个错误,因为我以前做过,虽然我不记得我是怎么做的了。
最后,我设法通过配置电子启动的 index.js 文件来解决它:
我受到英文 stackoverflow 网站的这个答案的启发