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.

Winston 3 and create-react-app throws Uncaught ReferenceError: stream is not defined

See original GitHub issue

Please tell us about your environment:

  • winston version? winston@3
  • node -v outputs: v10.11.0
  • Operating System? macOS
  • Language? ES6/7

What is the problem?

I create a new application with create-react-app and install winston 3.1.0 with npm install winston --save. After that I create a new file called myLogger.js and write logger from the quickstart:

import winston from 'winston';


const myLogger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [
        new winston.transports.Console({
            format: winston.format.simple()
        })
    ]
});

//
// 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') {
    myLogger.add(
        new winston.transports.Console({
            format: winston.format.simple(),
            level: 'debug'
        })
    );
}

export default myLogger;

After that I import the logger in the create-react-app created App.js:

import myLogger from './myLogger';

export default class App extends Component {

  componentDidMount() {
    myLogger.debug('Mounted!');
  }
  
  render() {return (</div>)}
}

If I start now the development server I get the error:

ReferenceError: stream is not defined
(anonymous function)
node_modules/winston/lib/winston/logger.js:631
  628 |   }]);
  629 | 
  630 |   return Logger;
> 631 | }(stream.Transform);
  632 | 

What do you expect to happen instead?

It just works on a freshly started create-react-app 😄

Other information

Here is the full stack:

logger.js:631 Uncaught ReferenceError: stream is not defined
    at Object.<anonymous> (logger.js:631)
    at Object../node_modules/winston/lib/winston/logger.js (logger.js:656)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Object../node_modules/winston/lib/winston/create-logger.js (create-logger.js:24)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Object../node_modules/winston/lib/winston.js (winston.js:55)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../src/myLogger.js (myLogger.js:1)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../src/App.js (App.css?da7c:45)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Module../src/index.js (index.css?02e3:45)
    at __webpack_require__ (bootstrap:782)
    at fn (bootstrap:150)
    at Object.0 (serviceWorker.js:127)
    at __webpack_require__ (bootstrap:782)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:25 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
MonVinescommented, Apr 10, 2019

Getting this error with Winston 3.2.

Uncaught TypeError: fs.existsSync is not a function at File._createLogDirIfNotExist (file.js:804) at new File (file.js:132) at Object.<anonymous> (mylogger.js:16) at webpack_require (bootstrap 284d16fcfe1dcfa44176:676) at fn (bootstrap 284d16fcfe1dcfa44176:87) at Object.<anonymous> (mymodule.js:5) at webpack_require (bootstrap 284d16fcfe1dcfa44176:676) at fn (bootstrap 284d16fcfe1dcfa44176:87) at Object.<anonymous> (app.js:21) at webpack_require (bootstrap 284d16fcfe1dcfa44176:676)

2reactions
DABHcommented, Dec 12, 2018

logform and winston-transport are transpiled too on master — all the Winston packages will receive a bump to npm when we publish

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Uncaught ReferenceError: Buffer is not defined
Recently I create a new version of react app and when I used mqtt.js ( not mqtt-react-hooks ) this bad Error was shown!!!...
Read more >
winston - npm
A multi-transport async logging library for Node.js. ... winston@3 ... Handling Uncaught Exceptions with winston; To Exit or Not to Exit.
Read more >
A Complete Guide to Winston Logging in Node.js - Better Stack
In this tutorial, we will explain how to install, set up, and use the Winston logger in a Node.js application. We'll go through...
Read more >
emitted 'error' event on writestream instance at - You.com
The 'error' event in Readable stream can be emitted at any time. It takes place when the hidden stream is not able to...
Read more >
How To Use Winston to Log Node.js Applications on Ubuntu ...
With these prerequisites in place, we can build our application and install Winston. Step 1 — Creating a Basic Node/Express App. A common...
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