Я могу использовать зависимость winston-daily-rotate-file
, используя require
.
var DailyRotateFile = require('winston-daily-rotate-file');
Но когда я пытаюсь импортировать, как показано ниже, это не работает. Как это решить?
import * as DailyRotateFile from 'winston-daily-rotate-file';
обычай-logger.js
import { createLogger, format, transports } from 'winston';
import * as DailyRotateFile from 'winston-daily-rotate-file';
import fs from 'fs';
import path from 'path';
const env = process.env.NODE_ENV || 'development';
const logDir = 'log';
if(!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
}
const dailyRotateFileTransport = new DailyRotateFile({
filename: `${logDir}/%DATE%-results.log`,
datePattern: 'YYYY-MM-DD',
maxSize: '1k'
})
const logger = createLogger({
level: env === 'development' ? 'debug' : 'info',
format: format.combine(
format.label({ label: path.basename(process.mainModule.filename)}),
//format.colorize(),
format.timestamp({
format: 'YYYY-MM-DD HH:mm:ss'
}),
format.json()
),
transports: [
new transports.Console({
level: 'info',
format: format.combine(
format.printf(
info => `${info.timestamp} ${info.level} [${info.label}]: ${info.message}`
)
)
}),
dailyRotateFileTransport
]
});
module.exports = logger;
При запуске приложения получаю следующую ошибку
var dailyRotateFileTransport = new DailyRotateFile({
^
TypeError: DailyRotateFile is not a constructor
import * as DailyRotateFile from 'winston-daily-rotate-file';
наrequire('winston-daily-rotate-file')
- person Avanthika   schedule 06.06.2019require
. Я хотел бы использовать импорт. - person Alexpandiyan Chokkan   schedule 06.06.2019winston-daily-rotate-file
? Если да, есть ли какая-либо другая последняя доступная зависимость? - person Alexpandiyan Chokkan   schedule 07.06.2019