S.Kiwi
S.Kiwi

Reputation: 1

javascript, electron, ipc doesn't give error or output

I'm new to js and electron, i keep getting no outputs or errors when running this code. Any help would be appreciated.

//Main.js
const ipcMain = require('electron').ipcMain;

ipcMain.on('x', function(event, arg) {
    console.log(arg);
});

// index.html
const { ipcRenderer } = require('electron').ipcRenderer;
ipc.send('x', "Hello");

Output

Upvotes: 0

Views: 84

Answers (1)

Waga Ya 1924
Waga Ya 1924

Reputation: 11

You should open the DevTools console in your main window; there are most certainly error messages displayed there telling you what's going wrong in your renderer process.

There are at least two issues in your code:

1/ The line

const { ipcRenderer } = require('electron').ipcRenderer;

should be either:

const { ipcRenderer } = require('electron');

or:

const ipcRenderer = require('electron').ipcRenderer;

2/ Once correctly defined, use ipcRenderer, not ipc:

ipcRenderer.send('x', "Hello");

Upvotes: 1

Related Questions