Closed BabyToy closed 6 years ago
can you add the stack trace?
This should be part of the winston-3 branch https://github.com/bithavoc/express-winston/tree/winston-3 @makrandgupta is on it.
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)```
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)
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)
@surfaceowl createLogger
is a function. so just use const logger = winston.createLogger(...
Solved this by: npm uninstall winston then: npm install winston@2.4.3
Great @Vascal thanks a lot for the info.
@Kogs -- thanks for the fix, that was it. Am still playing around with the new formatting options.
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
});
Yep, but you need to keep in mind that also the transports are configured in a different way with winston": "^3.0.0
.
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
@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.
@makrandgupta what's the ETA for winston-3
support?
summoning @makrandgupta
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.
Oki doki @makrandgupta
Any other volunteer? I’m gonna add a message to the Readme asking for contributors.
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;
},
}));
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!
A PR was merged recently (https://github.com/bithavoc/express-winston/pull/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 (https://github.com/bithavoc/express-winston/issues/163), I think this issue is redundant, so I'm going to close it.
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.