[英]Electron: Why occurs 'Uncaught ReferenceError: require is no defined.'?
I have a problem problem in my program using Electron.我在使用 Electron 的程序中遇到问题。
First, I was typing require()
code in 'main.js'.首先,我在“main.js”中输入
require()
代码。
const { app, BrowserWindow, globalShortcut, Menu, ipcMain } = require('electron')
Above code does not show an error from console.上面的代码没有显示来自控制台的错误。 And I have creating another source file
func.js
.我已经创建了另一个源文件
func.js
。
I was typing require()
code in func.js
.我在
func.js
输入require()
代码。
const { ipcRenderer, remote } = require('electron')
But above code shows an error in the console.但是上面的代码在控制台中显示了一个错误。
So I don't know what is wrong.所以我不知道出了什么问题。 The ES6 script uses the
import ()
statement, but I do not really know if there was an error in main.js
, but I do not know why other files fail. ES6脚本使用了
import ()
语句,但是我真的不知道main.js
是否有错误,但我不知道其他文件为什么会失败。
I got the same error & solved by adding the line bellow in main js file:我得到了同样的错误并通过在主 js 文件中添加以下行来解决:
from:从:
win = new BrowserWindow({
})
to:到:
win = new BrowserWindow({
webPreferences: {nodeIntegration: true},
})
当您在 html 和相应的 Javascript 文件之间引入连接 JS 代码时,就会发生这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.