require is not a function错误。
由于require可以直接请求运行客户机上的文件,容易引起安全问题,而在Electron 12以后的版本中被禁止。
解决方案
如果需要直接使用客户机上的文件,则需要设置web上下文contextIsolation选项为false。
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
修改后,本地使用require时,程序就正常跑起来了。
require is not a function错误。
由于require可以直接请求运行客户机上的文件,容易引起安全问题,而在Electron 12以后的版本中被禁止。
解决方案
如果需要直接使用客户机上的文件,则需要设置web上下文contextIsolation选项为false。
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
修改后,本地使用require时,程序就正常跑起来了。
评论 (0)