admin管理员组文章数量:1332980
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.
2 Answers
Reset to default 4In 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.
本文标签: javascriptElectron ipcMain undefinedStack Overflow
版权声明:本文标题:javascript - Electron ipcMain undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742344331a2457218.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论