datalust / winston-seq

A Winston v3 transport for Seq
Apache License 2.0
13 stars 3 forks source link

winston-seq - Unhandled Runtime Error ReferenceError: setImmediate is not defined #15

Closed ibrahimwithi closed 1 year ago

ibrahimwithi commented 2 years ago

I'm using winston-seq with next.js typescript and I got this error

Unhandled Runtime Error
ReferenceError: setImmediate is not defined

Source
new SeqTransport
.yarn\__virtual__\@datalust-winston-seq-virtual-cbfb7b8e00\0\cache\@datalust-winston-seq-npm-1.0.2-eb40de4950-0dd6ba735e.zip\node_modules\@datalust\winston-seq\dist\index.js (43:0)

logger.js

const winston = require('winston');
const { SeqTransport } = require('@datalust/winston-seq');

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.combine(
    winston.format.errors({ stack: true }),
    winston.format.json(),
  ),
  defaultMeta: {  application: 'UI' },
  transports: [
    new winston.transports.Console({
      format: winston.format.simple(),
    }),
    new SeqTransport({
      serverUrl: "ip:ip:ip",
      apiKey: "*********************",
      onError: (e => { console.error(e) }),
      handleExceptions: true,
      handleRejections: true,
    })
  ]
});

export default logger;
liammclennan commented 2 years ago

Hi @ibrahimwithi ,

To know exactly why you are getting this error I'd need to know more about your environment, but the ultimate cause is that winston-seq does not work in the browser. You can get past this error by defining a setImmediate function (as setTimeout(fn, 0)) or including a setImmediate polyfill, but if you do I expect that you will just run into the next error.

Also, Winston does not work in the browser either.

Rather than logging from the browser we recommend to send logs from your server code.