Skip to content

Commit

Permalink
logger: convert js to ts
Browse files Browse the repository at this point in the history
The error that is mentioned below can be fixed by enabling
esModuleInterop:

```
logger.ts:1:8 - error TS1259: Module '"/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 Oct 25, 2023
1 parent 7d643df commit 1241445
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion db_connect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const mongoose = require('mongoose');
const logger = require('./logger');
const logger = require('./logger').default;

// connect to database
const credentials = process.env.DB_USER
Expand Down
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 default 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 1241445

Please sign in to comment.