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

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

我将 winston 更新到版本 3.2.1 后,尝试热重新编译项目时出现错误(当我的项目启动并进行更改时)。

我尝试将所有依赖项更新到最新版本,但这没有帮助。 看来 webpack-hot-middleware 不能在最新版本的 winston 上正常工作。

如能提供解决此问题的建议,我将不胜感激。

错误:

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)

记录器配置:

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;

依赖版本:

winston@3.2.1
webpack-hot-middleware@2.25.0
webpack@4.41.2

查看此线程以获取解决方案。 https://github.com/winstonjs/winston/issues/1591

将记录器显式绑定回其方法

例如:

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

logger.info.bind(logger)