原因:因为没有对node.js和electron有一个系统的认识,所以原因我也不能确定,不过网上有些博客说过这个原因,感兴趣的可以搜索看一下。这里记录一下解决方案。
在新建窗口的时候,指定属性:
nodeIntegration:true
、contextIsolation:false
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
mainWindow = new browserWindow({
width: 500,
height: 300,
webPreferences:
{
nodeIntegration: true,
contextIsolation: false,
}
})