Since the electronic dependency in the browser is not real, that is, it is not overloaded from the web page from node_modules, but instead loaded at run time, the require statement causes errors, such as "fs", which are not found for me.
However, you can trick typescript like this:
if (typeof window['require'] !== "undefined") { let electron = window['require']("electron"); let ipcRenderer = electron.ipcRenderer; console.log("ipc renderer", ipcRenderer); }
Also, if you are writing a web application that is only supplemented by an electron when it works internally, this is the best way, since you do not need to add an electron depending on your webapp only when using communication parts.
source share