Cannot read property 'json' of undefined
See original GitHub issueUsing 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:
- Created 6 years ago
- Reactions:12
- Comments:10 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
It’s been three months and this is still the case.