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.

Cannot read property 'json' of undefined

See original GitHub issue

Using the example on the homepage, I get the following error:

/Users/owner/path/log.js:7
    format: winston.format.json(),
                          ^

TypeError: Cannot read property 'json' of undefined
    at Object.setupLogging (/Users/owner/path/log.js:7:27)
    at Object.<anonymous> (/Users/owner/path/server.js:35:8)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:578:3
const winston = require('winston');

function setupLogging(app) {
  const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [
      //
      // - Write to all logs with level `info` and below to `combined.log`
      // - Write all logs error (and below) to `error.log`.
      //
      new winston.transports.File({ filename: 'error.log', level: 'error' }),
      new winston.transports.File({ filename: 'combined.log' }),
    ],
  });

  //
  // If we're not in production then log to the `console` with the format:
  // `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
  //
  if (process.env.NODE_ENV !== 'production') {
    logger.add(new winston.transports.Console({
      format: winston.format.simple(),
      colorize: true,
    }));
  }

}

module.exports = {
  setupLogging,
};

package.json lists "winston": "^2.4.0"

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

54reactions
Xeoncrosscommented, Nov 10, 2017

Solved: The readme.md is for version 3. I have version 2.

The homepage shows v3 usage but npm still defaults to v2.

The homepage should probably mention this clearly.

screen shot 2017-11-10 at 4 51 49 pm

2reactions
isaachinmancommented, Jan 29, 2018

It’s been three months and this is still the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS: TypeError: Cannot read property 'json' of undefined
The TypeError happens in the return res.json(currency) , and it only happens when it's called by the CronJob. When I put new information...
Read more >
Cannot read property 'json' of undefined · Issue #762 - GitHub
Hey, @avinashadluri. As the error message says, the response JSON body is not a valid JSON. Here's how your response body is composed:...
Read more >
Cannot read properties of undefined (reading 'id') - TrackJS
This error can be thrown for a lot of reasons, as it is not uncommon to look for the id property of an...
Read more >
My result cannot read properties of undefined (reading 'length ...
Your result is not an array; it's an object which happens to have numeric property names. If you want to iterate over the...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
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