解決 Electron 5.0 版本出現 require is not defined 的問題


Electron已經發布了5.0正式版,升級后發現原來能運行的代碼報錯提示require is not defined

 

經查相關資料,原來官方在5.0版本修改了nodeIntegration的默認值,官方說明如下:

The default values of nodeIntegration and webviewTag are now false to improve security.

解決辦法:

修改創建BrowserWindow部分的相關代碼,設置屬性webPreferences.nodeIntegration為 true

let win = new BrowserWindow({
    webPreferences: {
        nodeIntegration: true
    }
})

 

 

相關資料:

https://github.com/electron/electron/pull/16235

https://stackoverflow.com/questions/55093700/electron-5-0-0-uncaught-referenceerror-require-is-not-defined


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM