winston version?_winston@2winston@3 node -v outputs:_ 8.11.1Am I right in thinking that Winston 3 is aiming to be compatible in Node and the browser? If so, the browser throws up on setImmediate, as it's a native Node thing. Currently, setImmediate is recommended to use this within new transports, so I can't quite see how this can work.
To re-produce:
Init somewhere:
import { createLogger, transports } from 'winston'
const consoleTransport = new transports.Console({ handleExceptions: true })
const logger = createLogger({
transports: [ consoleTransport ]
})
export default logger
Import and use somewhere in client-side code:
import logger from './logger'
logger.info('message for the browser console')
The browser console to log out the message
Sorry if I'm missing something here!
How are you bundling / do you have an example project? If I use webpack (and add
node: {
fs: 'empty'
}
to my webpack config to ignore the fs dependency of some transports) then I can e.g. use the console transport just fine (copy/pasting your code). Looks like there are some attempts at making browser support for setImmediate, e.g. https://github.com/YuzuJS/setImmediate, but also not sure exactly what errors you're getting since I can't reproduce yet with 3.0.
It's a Meteor app, so I don't have a huge amount of control over bundling.
I will post the error output later today if I get a second, but it's effectively setImmediate is undefined or similar.
Good shout on the Webpack settings though, I think that will work for most people. I just don't think I can tweak that in a Meteor app :(
Perhaps that polyfill will do the job actually. I'll give it a go!
Yeah, polyfilling setImmediate worked a charm — I guess I will close for now. Thanks!
Very cool, thanks for reporting back and letting us know!
@indexzero What do you think about adding a "browser readme" that contains tips for getting winston to work in various browsers/bundlers? Seems like different setups like webpack, meteor, etc. (see above) require different tricks to get winston working, it might be nice to document these all in one place so we can just refer people to there.
Hi! @jpsear how did you do to polyfill it? I tried to provide variable with webpack but without succeeding 😢
Here is my post: https://github.com/winstonjs/winston/issues/1489
@sneko I just installed setImmediate through npm: https://github.com/YuzuJS/setImmediate, then included it in my webpack bundle by importing it:
import 'setimmediate'
Then it's patched and available globally, on the window object
@jpsear thank you very much!
I misunderstood you at first: I tried to import it in the main webpack file, but I had to import it in a file that will be "compiled" by webpack ---> so import it at the root of your source files (e.g. main.ts)
@sneko Yep, you got it. No worries 👍
@jpsear Thanks, this fixed it for my Vue app.
npm install --save setimmediate
npm i
import 'setimmediate'; in the main.ts file
Most helpful comment
@sneko I just installed
setImmediatethrough npm: https://github.com/YuzuJS/setImmediate, then included it in my webpack bundle by importing it:Then it's patched and available globally, on the
windowobject