You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m encountering an issue with the bytecodePlugin when used in my electron app. The bug occurs in a file that uses the winston library for logging. While the app runs correctly without the bytecodePlugin, enabling it causes the app to throw the following error at runtime:
TypeError: Cannot read properties of undefined (reading 'info')
The issue seems related to how the plugin handles the winston library or its dynamic behavior. Without the plugin, everything works as expected.
Steps performed to Reproduce
Used the winston library for logging in logger.js:
constwinston=require('winston');constutil=require('util');const{ app, ipcMain }=require('electron');constpath=require('path');// Combine message and splat for proper formattingconstcombineMessageAndSplat=()=>({transform(info){const{[Symbol.for('splat')]: args=[], message }=info;info.message=util.format(message, ...args);returninfo;},});// Create the logger instanceconstcreateLogger=()=>winston.createLogger({format: winston.format.combine(winston.format.timestamp(),combineMessageAndSplat(),winston.format.printf((info)=>`${info.timestamp}${info.level}: ${info.message}`),),});// Create the renderer logger instanceconstcreateRendererLogger=()=>winston.createLogger({format: winston.format.combine(winston.format.timestamp(),combineMessageAndSplat(),winston.format.printf((info)=>`${info.timestamp}${info.level}: ${info.message}`),),});// Determine log directory pathconstlogDirPath=app.isPackaged ? app.getPath('logs') : './logs';// Initialize the main loggerconstlogger=createLogger();logger.add(newwinston.transports.File({level: 'debug',filename: path.join(logDirPath,'main.log'),options: {flags: 'a'},}));// In development, also log to the consoleif(!app.isPackaged){logger.add(newwinston.transports.Console());}// Initialize the renderer loggerconstrendererLogger=createRendererLogger();rendererLogger.add(newwinston.transports.File({level: 'debug',filename: path.join(logDirPath,'renderer.log'),options: {flags: 'a'},}));// In development, also log to the consoleif(!app.isPackaged){rendererLogger.add(newwinston.transports.Console());}// Handle IPC eventsipcMain.on('log-info',(_event,message)=>{rendererLogger.info(message);});ipcMain.on('log-error',(_event,message)=>{rendererLogger.error(message);});ipcMain.on('log-warn',(_event,message)=>{rendererLogger.warn(message);});module.exports={ logger, rendererLogger };
Added the bytecodePlugin to the electron vite config (electron.vite.config.js):
Build the application using electron-vite preview or electron-vite dev (If you build the application, everything will build inside out/ directory just fine. But when running it using electron-vite preview it throws error.
Run the application.
Expected Behavior
The app should run without errors when using the bytecodePlugin, with the winston logger functionality intact.
Observed Behavior
The app throws the following error when bytecodePlugin is enabled:
TypeError: Cannot read properties of undefined (reading 'info')
Additional Details
The issue is resolved when the bytecodePlugin is disabled, indicating it is related to how the plugin handles the winston library.
Externalizing winston in the Vite configuration did not resolve the issue.
I tried sandbox: false in my main window code but the issue persisted
I tried removing the ipc.* statements from the above logger code, yet the isse persisted.
Observations
I noticed a similar issue was raised in the context of electron-store (#568). In that case, the suggested workaround was to use an alternative library. While exploring alternatives can be helpful, it doesn’t fully address the underlying compatibility issues with the bytecodePlugin.
I believe resolving this would benefit the community by improving the usability of the bytecodePlugin with widely used libraries like winston. I would greatly appreciate any guidance or insights on addressing this issue. Your expertise and support can help make this plugin even more robust and user-friendly.
I have installed winston into dependencies only (see screenshot). However, I will try to install electron-winston and also scaffold the project from electron vite project in the recommended way and update in a couple of days.
@alex8088 I used the right way to scaffold the project and moved required code files into the new one and installed electron-winston and it is working fine Thanks for that!!.
But what is the way to configure log files in electron-winston? I want main.log and renderer.log.
Describe the bug
I’m encountering an issue with the
bytecodePlugin
when used in my electron app. The bug occurs in a file that uses thewinston
library for logging. While the app runs correctly without thebytecodePlugin
, enabling it causes the app to throw the following error at runtime:TypeError: Cannot read properties of undefined (reading 'info')
Complete Error:
The issue seems related to how the plugin handles the
winston
library or its dynamic behavior. Without the plugin, everything works as expected.Steps performed to Reproduce
winston
library for logging inlogger.js
:bytecodePlugin
to the electron vite config (electron.vite.config.js
):Build the application using
electron-vite preview
orelectron-vite dev
(If you build the application, everything will build inside out/ directory just fine. But when running it usingelectron-vite preview
it throws error.Run the application.
Expected Behavior
The app should run without errors when using the
bytecodePlugin
, with thewinston logger
functionality intact.Observed Behavior
The app throws the following error when
bytecodePlugin
is enabled:Additional Details
bytecodePlugin
is disabled, indicating it is related to how the plugin handles thewinston
library.winston
in the Vite configuration did not resolve the issue.sandbox: false
in my main window code but the issue persistedObservations
I noticed a similar issue was raised in the context of
electron-store
(#568). In that case, the suggested workaround was to use an alternative library. While exploring alternatives can be helpful, it doesn’t fully address the underlying compatibility issues with thebytecodePlugin
.I believe resolving this would benefit the community by improving the usability of the
bytecodePlugin
with widely used libraries likewinston
. I would greatly appreciate any guidance or insights on addressing this issue. Your expertise and support can help make this plugin even more robust and user-friendly.See also: #568
Electron-Vite Version
2.3.0
Electron Version
33.3.1
Vite Version
5.4.11
Validations
The text was updated successfully, but these errors were encountered: