Below is my simple code to configure winston. But its failing at runtime when node.js server started,
var winston = require('winston');
winston.log('info', 'Hello distributed log files!');
winston.info('Hello again distributed logs');
winston.level = 'debug';
Exception:
Uncaught TypeError: Cannot read property 'write' of undefined
at exports.Console.Console.log (http://localhost:8080/public/bundle.js:110094:19)
at transportLog (http://localhost:8080/public/bundle.js:109429:15)
at http://localhost:8080/public/bundle.js:45186:13
at _each (http://localhost:8080/public/bundle.js:45086:9)
at Object.async.each (http://localhost:8080/public/bundle.js:45185:9)
at exports.Logger.Logger.log (http://localhost:8080/public/bundle.js:109441:9)
at Object.winston.(anonymous function) [as log] (http://localhost:8080/public/bundle.js:28305:34)
at Object.defineProperty.value (http://localhost:8080/public/bundle.js:57848:9)
at __webpack_require__ (http://localhost:8080/public/bundle.js:20:30)
at Object.
server.js file:
var path = require('path');
var express = require('express');
var webpack = require('webpack');
var config = require('./webpack.config.dev');
var app = express();
var compiler = webpack(config);
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(express.static(__dirname))
app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, '/index.html'));
});
app.listen(8080, 'localhost', function(err) {
if (err) {
console.log(err);
return;
}
console.log('Listening at http://localhost:8080');
});
Somehow I am able to solve this issue, but its failing throwing
Uncaught TypeError: fs.stat is not a function
Can anyone please help?
Can anyone please help?
@KalpanaPagariya Did you ever find a fix for this? I'm currently seeing it as well.
@KalpanaPagariya you wrote that you were somehow able to solve this issue - i just ran into the same issue - how did you solve it?
+1
Winston is not written for browser usage. http://localhost:8080/public/bundle.js:110094:19 shows that you are running in the browser and not on node process.
But there is a way to tweak the console transport for browser usage:
In my Gruntfile.js on string-replace task I have this configuration:
winston: {
files: [{
src: "node_modules/winston/lib/winston.js",
dest: joinPath(env.dir.build, "winston.js"),
}],
options: {
replacements: [
{
pattern: /process.stdout.write/g,
replacement: "console.log",
},
{
pattern: /process.stderr.write/g,
replacement: "console.error",
},
],
},
},
Before bundling the sources, copy winston.js by string-replacing the node-process relevant process.stdout and process.stderr calls to the browser console relevant calls. Webpack now needs to pack this transformed winston.js file.
I know, this is not the cleanest way, but since the Winston staff denies to adapt Winston for browsers, this is the fastest way to have always the newest Winston version running in browsers, without the need to fork the project and maintain it afterwards for a long time.
EDIT:
For webpack, there is a string-replace-webpack-plugin.
This should be fixed by https://github.com/winstonjs/winston/pull/1279 鈥撀爌lease consider upgrading to the next version of [email protected] when it ships tomorrow.
TypeError: fs.stat is not a function
in package.json "winston": "^3.1.0"
Did you resolve?