Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

winston.format is undefined #1093

Closed
ErayTuncer opened this issue Oct 9, 2017 · 5 comments
Closed

winston.format is undefined #1093

ErayTuncer opened this issue Oct 9, 2017 · 5 comments

Comments

@ErayTuncer
Copy link

I have just wanted to create a simple logger with the code below:

const winston = require('winston');

// init logger
const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new winston.transports.File({ filename: 'coin-error.log', level: 'error' }),
    new winston.transports.File({ filename: 'coin-combined.log' })
  ]
});

However, somehow I get this error:

/pathtofile.../handler-coin.js:9
  format: winston.format.json(),
                        ^
TypeError: Cannot read property 'json' of undefined

"winston": "^2.4.0"

@jcrugzz
Copy link
Contributor

jcrugzz commented Oct 9, 2017

@ErayTuncer As per the README, the docs are for the rc of winston@3. If you npm i winston@next --save you will get the correct version where this example will work.

@indexzero
Copy link
Member

indexzero commented Oct 9, 2017

@jcrugzz is correct. Expect to have winston@3.0.0 out of RC by the end of next week.

@danyfoo
Copy link

danyfoo commented Oct 9, 2017

How can I create the logger with version 2.4.0?

@mempf
Copy link
Contributor

mempf commented Oct 9, 2017

The documentation shown on NPM is still for winston 2.x:
https://www.npmjs.com/package/winston

Or by using the v2.4 tag on github:
https://github.com/winstonjs/winston/tree/2.4.0

@myfunc
Copy link

myfunc commented Dec 25, 2023

Solution that works for me:

in tsconfig.json add "esModuleInterop": true

That's actually really old thread, but I faced with that in Dec 2023.
I hope my solution will help someone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants