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

Exception: winston.Logger is not a constructor #175

Closed
BabyToy opened this issue Jun 13, 2018 · 21 comments
Closed

Exception: winston.Logger is not a constructor #175

BabyToy opened this issue Jun 13, 2018 · 21 comments

Comments

@BabyToy
Copy link

BabyToy commented Jun 13, 2018

An exception is thrown when initializing express-winston, apparently the error is in:
express-winston/index.js

I think the latest update to Winston broke this build.

@bithavoc
Copy link
Owner

can you add the stack trace?

@lqshow
Copy link

lqshow commented Jun 13, 2018

winston UPGRADE-3.0.md

image

@bithavoc
Copy link
Owner

This should be part of the winston-3 branch https://github.com/bithavoc/express-winston/tree/winston-3 @makrandgupta is on it.

@BabyToy
Copy link
Author

BabyToy commented Jun 14, 2018

Attached is the stack trace:

TypeError: winston.Logger is not a constructor
    at new winstonLogger (common\logWinston.js:28:20)
    at Object.<anonymous> (common\gracefulExit.js:8:17)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)```

@fega
Copy link

fega commented Jun 15, 2018

 options.winstonInstance = options.winstonInstance || (new winston.Logger ({ transports: options.transports }));
                                                          ^

TypeError: winston.Logger is not a constructor
    at Object.errorLogger (/mnt/c/Users/Acer/projects/coachtools/backend/node_modules/express-winston/index.js:120:59)
    at Object.<anonymous> (/mnt/c/Users/Acer/projects/coachtools/backend/src/server.js:99:28)
    at Module._compile (module.js:652:30)
    at loader (/mnt/c/Users/Acer/projects/coachtools/backend/node_modules/babel-register/lib/node.js:144:5)
    at Object.require.extensions.(anonymous function) [as .js] (/mnt/c/Users/Acer/projects/coachtools/backend/node_modules/babel-register/lib/node.js:154:7)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)

@surfaceowl
Copy link

After upgrading Winston to 3.0.0, and updating our code to use: const logger = new (winston.createLogger)({ we are getting a similar "not a constructor error"

How should we troubleshoot and fix this?

const logger = new (winston.createLogger)({ 
               ^ 
TypeError: winston.createLogger is not a constructor 
    at Object.<anonymous> (/app/server/src/helpers/logger.js:6:16) 
    at Module._compile (internal/modules/cjs/loader.js:702:30) 
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) 
    at Module.load (internal/modules/cjs/loader.js:612:32) 
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12) 
    at Function.Module._load (internal/modules/cjs/loader.js:543:3) 
    at Function.wrappedLoad [as _load] (/app/server/node_modules/newrelic/lib/shimmer.js:324:38) 
    at Module.require (internal/modules/cjs/loader.js:650:17) 
    at require (internal/modules/cjs/helpers.js:20:18) 
    at Object.<anonymous> (/app/server/src/helpers/error-helper.js:1:78) 
    at Module._compile (internal/modules/cjs/loader.js:702:30) 
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) 
    at Module.load (internal/modules/cjs/loader.js:612:32) 
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12) 
    at Function.Module._load (internal/modules/cjs/loader.js:543:3) 
    at Function.wrappedLoad [as _load] (/app/server/node_modules/newrelic/lib/shimmer.js:324:38) 
    at Module.require (internal/modules/cjs/loader.js:650:17) 
    at require (internal/modules/cjs/helpers.js:20:18) 
    at Object.<anonymous> (/app/server/src/core/express.js:18:21) 
    at Module._compile (internal/modules/cjs/loader.js:702:30) 
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) 
    at Module.load (internal/modules/cjs/loader.js:612:32)

@Kogs
Copy link

Kogs commented Jun 25, 2018

@surfaceowl createLogger is a function. so just use const logger = winston.createLogger(...

@Vascal
Copy link

Vascal commented Jun 26, 2018

Solved this by:
npm uninstall winston
then:
npm install winston@2.4.3

@juan55860
Copy link

Great @Vascal thanks a lot for the info.

@surfaceowl
Copy link

@Kogs -- thanks for the fix, that was it. Am still playing around with the new formatting options.

@DanGDroid
Copy link

as @Kogs said:
if using "winston": "^3.0.0" do:

var logger = winston.createLogger({
  
 transports: transports
});

and if using older "winston": "^2.4.0" do:

var logger = new winston.Logger({
  
 transports: transports
});

@Kogs
Copy link

Kogs commented Jul 3, 2018

Yep, but you need to keep in mind that also the transports are configured in a different way with winston": "^3.0.0.

@hiro5id
Copy link

hiro5id commented Jul 9, 2018

This isn't really solved by installing older version of winston. It is only a temporary workaround.
We still need a proper fix for this so that we can use the latest version of winston.

Solved this by:
npm uninstall winston
then:
npm install winston@2.4.3

@ghCarol
Copy link

ghCarol commented Jul 16, 2018

@hiro5id I agree. The problem is not fixed thoroughly. I am using 'express-winston' in addition with 'winston' like this:

app.use(expressWinston.logger({
  transports: [
    new (winston.transports.Console)({
      json: true,
      colorize: true
    }),
    new winston.transports.File({
      filename: 'logs/success.log'
    })
  ]
}))

Here I'm using "express-winston": "^2.5.1"
If I use winston@3.0.0, this problem pops out. I can only replace it with the older version. However, I still want to keep up with the latest version of winston if possible.

@bithavoc
Copy link
Owner

@makrandgupta what's the ETA for winston-3 support?

@bithavoc
Copy link
Owner

summoning @makrandgupta

@makrandgupta
Copy link
Collaborator

My apologies for going dark. I have had no time to work in this. Everything that I did is already pushed into the v3 branch. I could assist another developer make the port happen but won't be able to take point on this one.

@bithavoc
Copy link
Owner

Oki doki @makrandgupta

Any other volunteer? I’m gonna add a message to the Readme asking for contributors.

@lcssanches
Copy link

Guys,

I was able to get it running with this:

app.use(expressWinston.errorLogger({
  winstonInstance: winston.createLogger({
    transports: [
      new winston.transports.Console({
        json: true,
        colorize: true
      })
    ]
  }),
  exceptionToMeta: function(err){
    return err;
  },
}));

@blendedmarket
Copy link

blendedmarket commented Aug 7, 2018

Getting an error when creating an instance of the logger?

Anyone who has used this site, make sure to replace all instances of
const logger = new (winston.logger)
replace with -
const logger = (winston.createLogger)({
drop the new and rename the funciton createLogger and you are good to go!

dmichelin pushed a commit to dmichelin/express-winston that referenced this issue Aug 7, 2018
dmichelin pushed a commit to dmichelin/express-winston that referenced this issue Aug 9, 2018
@rosston
Copy link
Collaborator

rosston commented Aug 10, 2018

A PR was merged recently (#178) to clarify that the current version of express-winston only supports winston <3. I realize this "fix" is not ideal, but it does prevent users from seeing the error reported here and allows us to add winston@3 support when we're ready.

Between the above change, and the fact that we have an issue open for adding winston@3 support (#163), I think this issue is redundant, so I'm going to close it.

@rosston rosston closed this as completed Aug 10, 2018
Repository owner locked as resolved and limited conversation to collaborators Aug 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests