若在electron中使用serialport
有一版demo是 electron-quick-start,clone到本地启动后提示require is not defined
如果你去改script type类型就越找越远了....
你只要去加两行
nodeIntegration: true, // to allow require
contextIsolation: false, // allow use with Electron 12+
就好了
main.js
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true, // to allow require
contextIsolation: false, // allow use with Electron 12+
preload: path.join(__dirname, 'preload.js')
}
})
网友评论