Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

winston-elasticsearch: TypeError: Elasticsearch is not a constructor

I'm using winston-elasticsearch on an express server, I just wrote the same code as in the documentation

var winston = require('winston');
var Elasticsearch = require('winston-elasticsearch');

var esTransportOpts = {
  level: 'info'
};
var logger = winston.createLogger({
  transports: [
    new Elasticsearch(esTransportOpts)
  ]
});

when i run the server, I get this error:

TypeError: Elasticsearch is not a constructor

I have installed the lates versions "winston": "^3.2.1" and "winston-elasticsearch": "^0.8.8"

like image 247
asma Avatar asked Dec 10 '22 00:12

asma


1 Answers

@asma's suggestion, downgrade to 0.7.x, did indeed fix this error for me. However, that left me stuck at an outdated version, getting a different error that is fixed in the latest version.

The issue mentioned by @joe is closed now. It explains that everyone's gotten used to the breaking change by adjusting their syntax. However, the README still has the old syntax.

I was able to get the latest version (0.8.8) working by adjusting the example as follows:

var winston = require('winston');
var winstonElasticSearch = require('winston-elasticsearch');

var esTransportOpts = {
  level: 'info'
};
var logger = winston.createLogger({
  transports: [
    new winstonElasticSearch.ElasticsearchTransport(esTransportOpts)
  ]
});
like image 159
joecullin Avatar answered Feb 16 '23 01:02

joecullin