在研究 渲染進程和主程序之前通信時,就在renderer.js 文件中寫第一句代碼
const {ipcRenderer} = require('electron').ipcRenderer
就報錯,然后我就尋尋覓覓,尋尋覓覓呀,估算也找了小半天時間,然后,
在我冷靜下來仔細看看renderer.js 文件,在文件開頭就有這樣一句話
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off.
Use `preload.js` to
// selectively enable features needed in the rendering
// process.
這句話很重要就是,理解起來就是,這個renderer.js 不可以使用node.js,如果要使用,你需要去,啟動XXXXX
看到這句話,百度起來就快了,網上給的答案在主進程中創建webPreference中修改他
nodeIntegration:true(默認的是false)
自問,我為啥呢么二,我也寫了,然后再運行,報錯依舊,我就很着急呀,why,
划重點:我拼錯了,,,如果你也入坑,請仔細仔細檢查,你是不是也把這個寫錯了。正確的寫法是
webPreferences: {
//注意大小寫
nodeIntegration:true,
preload: path.join(__dirname, 'preload.js')
}