javascript - Electron ipcMain undefined - Stack Overflow

The following code produces an errorconst ipcMain = require('electron').ipcMain;ipcMain.on(&

The following code produces an error

const ipcMain = require('electron').ipcMain;
ipcMain.on('open-file-dialog', function (event) {});

This error is thrown in console:

Uncaught TypeError: Cannot read property 'on' of undefined

As mentioned on this question, i also tried using

const ipcMain = require('ipc-main');

but am getting the same error.

Seems that ipcRenderer is defined in the electron package, but not ipcMain. How do i fix this? Already tried reinstalling the latest nodejs and running npm install on a fresh checkout.

The following code produces an error

const ipcMain = require('electron').ipcMain;
ipcMain.on('open-file-dialog', function (event) {});

This error is thrown in console:

Uncaught TypeError: Cannot read property 'on' of undefined

As mentioned on this question, i also tried using

const ipcMain = require('ipc-main');

but am getting the same error.

Seems that ipcRenderer is defined in the electron package, but not ipcMain. How do i fix this? Already tried reinstalling the latest nodejs and running npm install on a fresh checkout.

Share Improve this question edited May 23, 2017 at 12:10 CommunityBot 11 silver badge asked May 15, 2017 at 6:57 TomTom 2,6311 gold badge18 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

In Renderer process you should use the counterpart of ipcMain, which is ipcRenderer. See docs of ipcMain for code examples

Your corrected code would look like

const { ipcRenderer } = require('electron');
ipcRenderer.on('open-file-dialog', function (event) {});

Problem seems to be that I loaded the module from a renderer process. Moving the ipcMain related code to the main module (unsurprisingly) solved the issue.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742344332a4426242.html

相关推荐

  • javascript - Electron ipcMain undefined - Stack Overflow

    The following code produces an errorconst ipcMain = require('electron').ipcMain;ipcMain.on(&

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信