Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error after update winston to version 3.2.1. TypeError: self._addDefaultMeta is not a function

After I updated winston to version 3.2.1, I get an error while trying to hot recompile the project (when my project is started and I make changes).

I tried to update all my dependencies to the latest versions, but this did't help. It seems webpack-hot-middleware doesn't work correctly with the latest version of winston.

I would be grateful for advice on how to fix this.

Error:

i 「wdm」: Compiling...
D:\Dev\MyProjectName\node_modules\winston\lib\winston\create-logger.js:80
        self._addDefaultMeta(info);
             ^

TypeError: self._addDefaultMeta is not a function
    at Object.DerivedLogger.<computed> [as log] (D:\Dev\MyProjectName\node_modules\winston\lib\winston\create-logger.js:80:14)
    at onInvalid (D:\Dev\MyProjectName\node_modules\webpack-hot-middleware\middleware.js:27:24)
    at SyncHook.eval [as call] (eval at create (D:\Dev\MyProjectName\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:9:1)
    at SyncHook.lazyCompileHook (D:\Dev\MyProjectName\node_modules\tapable\lib\Hook.js:154:20)
    at Watchpack.<anonymous> (D:\Dev\MyProjectName\node_modules\webpack\lib\Watching.js:142:33)
    at Object.onceWrapper (events.js:300:26)
    at Watchpack.emit (events.js:210:5)
    at Watchpack._onChange (D:\Dev\MyProjectName\node_modules\watchpack\lib\watchpack.js:118:7)
    at Watchpack.<anonymous> (D:\Dev\MyProjectName\node_modules\watchpack\lib\watchpack.js:99:8)
    at Watcher.emit (events.js:210:5)
    at D:\Dev\MyProjectName\node_modules\watchpack\lib\DirectoryWatcher.js:101:9
    at Array.forEach (<anonymous>)
    at DirectoryWatcher.setFileTime (D:\Dev\MyProjectName\node_modules\watchpack\lib\DirectoryWatcher.js:99:42)
    at DirectoryWatcher.<anonymous> (D:\Dev\MyProjectName\node_modules\watchpack\lib\DirectoryWatcher.js:312:12)
    at D:\Dev\MyProjectName\node_modules\graceful-fs\polyfills.js:285:20
    at FSReqCallback.oncomplete (fs.js:159:5)

Logger config:

const winston = require('winston');

const transports = [];

const alignColorsAndTime = winston.format.combine(
  winston.format.timestamp({
    format: 'HH:MM:ss:SS DD.MM.YY',
  }),
  winston.format.printf(
    info => `${info.timestamp} ${info.level}:${info.message}`,
  ),
);

/**
 * Console transporter
 */
transports.push(new winston.transports.Console({
  level: config.logging.console.level,
}));

const logger = winston.createLogger({
  level: 'debug',
  transports,
  format: winston.format.combine(winston.format.colorize(), alignColorsAndTime),
  exitOnError: false,
});

module.exports = logger;

Dependency versions:

[email protected]
[email protected]
[email protected]
like image 501
im1x Avatar asked Oct 28 '25 19:10

im1x


1 Answers

Check this thread for solution. https://github.com/winstonjs/winston/issues/1591

bind logger back explicitly to its methods

ex:

const logger = winston.createLogger({
  transports: [
    new winston.transports.Console()
  ]
}); 

logger.info.bind(logger)
like image 103
Joseph Peeka Avatar answered Oct 31 '25 11:10

Joseph Peeka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!