Open hira-00 opened 3 years ago
The error message "Cannot read property 'length' of undefined" suggests that the transport.log object is undefined, and you're trying to access its 'length' property. Implementing the null safety in your code will solve this problem.
const target = !isStream(transport) || transport?.log?.length > 2 ? new LegacyTransportStream({ transport }) : transport;
"?."--- using this while trying to access the length of the log property will resolve this issue. In JavaScript, the ?. (optional chaining) is an operator introduced in ECMAScript 2020 (ES11) that allows you to safely access properties or call methods on an object without having to explicitly check if the object and its properties are defined. It helps to avoid "Cannot read property 'x' of undefined" or "Cannot read property 'y' of null" errors.
Hope this helps. Good luck!
Please tell us about your environment:
winston
version?winston@2
winston@3
(3.3.3)node -v
outputs: v14.16.0What is the problem?
My logger initialisation code with Winston (inside my MERN app) exists over here on stack overflow.
What do you expect to happen instead?
the error occurs when the terminal is in idle mode, but the app is running, so the error shouldn't be appearing at all. I think this is an internal Winston bug based on this previous issue.
Other information
This is my stack trace
Also, the issue occurs at line 345 of logger.js in Winston inside the add function w/
transport.log.length > 2
Does anyone over here have a solution to this?