Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: setImmediate is not defined #1489

Closed
sneko opened this issue Oct 2, 2018 · 4 comments
Closed

Uncaught ReferenceError: setImmediate is not defined #1489

sneko opened this issue Oct 2, 2018 · 4 comments

Comments

@sneko
Copy link

sneko commented Oct 2, 2018

Hi,

I get errors as soon as I try to write logs with winston inside my Vue.js project. Here is the code:

// Create a logger to adjust logs
const logger = winston.createLogger({
  level: "debug",
  transports: [
    new winston.transports.Console(),
  ]
});

console.log(1111);
logger.debug("dqsqsdqsd");
console.log(2222);

And the "2222" is never showed, it fails before with the following error:

logger.js?e7af:237 Uncaught ReferenceError: setImmediate is not defined
    at Console.log (console.js?bc48:43)
    at Console._write (index.js?d13f:81)
    at doWrite (_stream_writable.js?dc14:428)
    at writeOrBuffer (_stream_writable.js?dc14:417)
    at Console.Writable.write (_stream_writable.js?dc14:334)
    at DerivedLogger.ondata (_stream_readable.js?ad71:619)
    at DerivedLogger.EventEmitter.emit (events.js?faa1:81)
    at addChunk (_stream_readable.js?ad71:291)
    at readableAddChunk (_stream_readable.js?ad71:278)
    at DerivedLogger.Readable.push (_stream_readable.js?ad71:245)

I don't understand what's the problem. There is not that much information about that kind of error :/

I'm using Winston 3.1.0 inside a TypeScript project.

Do you have any idea that could help please?

Thank you,

@sneko
Copy link
Author

sneko commented Oct 2, 2018

browserify/timers-browserify#28

May it could help?

@sneko
Copy link
Author

sneko commented Oct 2, 2018

That's funny, I read a post (browserify/timers-browserify#25 (comment)) that advises to inject these variables globally to make it working, so in my Vue settings I custom webpack with:

    config
      .plugin('provide')
      .use(webpack.ProvidePlugin, [{
        setImmediate: ['setimmediate', 'setImmedate'],
        clearImmediate: ['setimmediate', 'clearImmedate']
      }]);

Now I'm able to reach "setImmediate" in my Chrome console, but Winston is still showing me the error... when looking at sourceMap the error is here:

  log(info, callback) {
    setImmediate(() => this.emit('logged', info));

Any idea @indexzero ?

EDIT: I also removed my lock file and the node_modules directory but it doesn't change anything 😢

EDIT2: Maybe winston plugin could use setImmediate from a package that suppports browser compatibility? (https://github.com/YuzuJS/setImmediate)

@sneko
Copy link
Author

sneko commented Oct 2, 2018

I'm using a workaround thanks to @jpsear (#1354 (comment)). I'm leaving this issue opened until having a feedback from one of the maintainer 🔨

@DABH
Copy link
Contributor

DABH commented Dec 28, 2018

Yeah, that workaround is a good way to go I think. Perhaps we can bake that workaround into winston itself, or make a "browser faq" like I suggested in #1354. Let's keep #1354 open for further discussion, would be good to do something there. Thanks!

@DABH DABH closed this as completed Dec 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants