question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

padLevels warning appears in Winston@3

See original GitHub issue

Please tell us about your environment:

  • _winston version?
    • winston@2
    • [ x] winston@3
  • _node -v outputs: v14.13.1
  • _Operating System: Linux
  • _Language: ES6

What is the problem?

padLevels warning (“Accessing non-existent property ‘padLevels’ of module exports inside circular dependency”) appears when using Winston 3.3.3. Issue has been mostly related to Winston@2

What do you expect to happen instead?

padLevels does not occur

Other information

Logger is created as so

var appRoot = require('app-root-path');
var winston = require('winston');
const colorizer = winston.format.colorize();

// define the custom settings for each transport (file, console)
var options = {
    console: {
        handleExceptions: true,
        level: "info",
        format: winston.format.combine(
            winston.format.timestamp({format: "HH:mm:ss"}),
            winston.format.simple(),
            winston.format.printf(msg =>
                colorizer.colorize(msg.level, `${msg.timestamp} - ${msg.level}: ${msg.message}`)
            ),
        )
    },
};

// instantiate a new Winston Logger with the settings defined above
const logger = new winston.createLogger({
    transports: [
        new winston.transports.Console(options.console)
    ],
    exitOnError: false, // do not exit on handled exceptions
});

// create a stream object with a 'write' function that will be used by `morgan`
logger.stream = {
    write: function(message, encoding) {
        // use the 'info' log level so the output will be picked up by both transports (file and console)
        logger.info(message);
    },
};

module.exports = logger;

A line such as logger.info("NPM package " + viewEngineData.expressName + " installed") will cause the warning. unsure if my Winston setup is wrong but seem to be using only Winston3 functions

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

1reaction
flotwigcommented, Nov 8, 2021

We also get this in winston@2.4.4. This patch suppresses the warning:

diff --git a/node_modules/winston/lib/winston/common.js b/node_modules/winston/lib/winston/common.js
index 8ed9973..53cf4cd 100644
--- a/node_modules/winston/lib/winston/common.js
+++ b/node_modules/winston/lib/winston/common.js
@@ -32,7 +32,7 @@ exports.setLevels = function (target, past, current, isDefault) {
   }
 
   target.levels = current || config.npm.levels;
-  if (target.padLevels) {
+  if (target.hasOwnProperty('padLevels') && target.padLevels) {
     target.levelLength = exports.longestElement(Object.keys(target.levels));
   }
 

1reaction
DavidCockerillcommented, Jul 23, 2021

Yeah, switch to Pino 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing non-existent property 'padLevels' of module exports ...
(node:4909) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency (Use `node --trace-warnings .
Read more >
logging in JavaScript with Winston.js - ZetCode
Winston tutorial shows how to do logging in JavaScript with Winston.js, and demonstrates logging in several code examples.
Read more >
foreverjs/forever - Gitter
(node:733992) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency. Igor Savin. @kibertoad. This is a Winston ...
Read more >
winston - npm
Console({ level: 'warn' }), file: new winston.transports.File({ filename: 'combined.log', ...
Read more >
Accessing non-existent property 'count' of module exports ...
(node:10624) Warning: Accessing non-existent property 'count' of module exports ... with these dependencies the same error is showing again.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found