megahertz / electron-log

Simple logging module Electron/Node.js/NW.js application. No dependencies. No complicated configuration.
MIT License
1.27k stars 124 forks source link

The "initialize" method encountered an error in main process! #369

Closed WangJM001 closed 5 months ago

WangJM001 commented 9 months ago

Error Info

Error occurred in handler for 'ELECTRON_LOG': Error: No handler registered for 'ELECTRON_LOG'

Reason

I checked the code and found that it's caused by 'process.type' being 'undefined' in the development environment.

function getIpc() {
  if (process.type === 'browser' && electron?.ipcMain) {
    return electron.ipcMain;
  }

  if (process.type === 'renderer' && electron?.ipcRenderer) {
    return electron.ipcRenderer;
  }

  return null;
}

Can it be adjusted?

function getIpc() {
  if (process.type === 'renderer' && electron?.ipcRenderer) {
    return electron.ipcRenderer;
  }

  return electron.ipcMain;
}
megahertz commented 9 months ago

Thanks @WangJM001. Does it solve the issue or that's just an assumption? Could you provide more information about your bundler and the related environment?

johannesjo commented 6 months ago

I have a similar error with electron 28.0.0. When using the initialize function in the main process I get the following error:

Cannot read properties of undefined (reading 'initializeFn')
    at initialize (/home/user/www/super-productivity/node_modules/electron-log/src/core/Logger.js:120:10)
megahertz commented 5 months ago

This part was rewritten entirely in v5.1.0, so I think it should be fixed.