Skip to content

Commit

Permalink
logger: convert js to ts
Browse files Browse the repository at this point in the history
Winston can only be default-imported with the esModuleInterop
flag enabled:

```
logger.ts:1:8 - error TS1259: Module '"C:/Users/PC/projs/bot/node_modules/winston/index"' can only be default-imported using the 'esModuleInterop' flag

1 import winston from 'winston';
         ~~~~~~~

  node_modules/winston/index.d.ts:213:1
    213 export = winston;
        ~~~~~~~~~~~~~~~~~
    This module is declared with 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
```
  • Loading branch information
Mersho committed Dec 27, 2023
1 parent 2fbe162 commit 68ed5f0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions logger.js → logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const winston = require('winston');
import winston from 'winston';

const level = process.env.LOG_LEVEL || 'notice';

Expand All @@ -9,9 +9,8 @@ const logger = winston.createLogger({
}),
winston.format.colorize(),
winston.format.printf(info => {
return `[${info.timestamp}] ${info.level}: ${info.message} ${
info.stack ? info.stack : ''
}`;
return `[${info.timestamp}] ${info.level}: ${info.message} ${info.stack ? info.stack : ''
}`;
})
),
levels: winston.config.syslog.levels,
Expand All @@ -24,4 +23,5 @@ const logger = winston.createLogger({
exitOnError: false,
});

module.exports = logger;

export { logger };
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"strict": true,
"esModuleInterop": true,
}
}

0 comments on commit 68ed5f0

Please sign in to comment.