Electron+Angular2+webpack cannot require electron in renderer process


#1

Try to implement IPC between main and renderer process.
At renderer process(Angular2), when I try to write:
constructor() { const electron = require('electron'); }
Start electron it gives me:
Uncaught Error: ENOENT: no such file or directory, open 'C:\path.txt'fs.openSync @ fs.js:640module.(anonymous function) @ ELECTRON_ASAR.js:178fs.readFileSync @ fs.js:508fs.readFileSync @ ELECTRON_ASAR.js:511(anonymous function) @ index.js:4(anonymous function) @ index.js:4__webpack_require__ @ bootstrap 747b3ca…:50(anonymous function) @ app.ts:5__webpack_require__ @ bootstrap 747b3ca…:50webpackJsonpCallback @ bootstrap 747b3ca…:21(anonymous function) @ app.js:1

The project’s root folder is not under C:. Also under node_modules electron package I saw a path.txt with follow content:
dist/electron.exe

Other require in renderer works fine(like fs)

Any help would be thanks.


#2

So they way I got it working was include this in the angular index.html

then in the service where your communicating to electron use
declare global {
interface Window {
require: any;
}
}
const electron = window.require(‘electron’);