Encountered an error with Winston and Elasticsearch integration: "TypeError: Elasticsearch is not a constructor

I recently implemented winston-elasticsearch on my express server by following the code provided in the documentation

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

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

Upon starting the server, I encountered the following error:

TypeError: Elasticsearch is not a constructor

Both the "winston" and "winston-elasticsearch" packages are up-to-date with versions "^3.2.1" and "^0.8.8", respectively.

Answer №1

@asma's recommendation to switch back to version 0.7.x resolved the error I was experiencing. However, this meant I was using an outdated version that led to a new error fixed in the most recent release.

Regarding @joe's concern, it seems that the issue has been addressed and users have adapted to the changes by adjusting their syntax. Nonetheless, the README still contains information about the old syntax.

To make version 0.8.8 work for me, I had to modify the example code as shown below:

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

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

Answer №2

To ensure compatibility with Winston 3.x and Elasticsearch 6.0 onwards, you should opt for version 0.7.0. For users of Elasticsearch 6.0 and newer, version 0.6.0 is recommended. If you are working with Elasticsearch 5.0 or later versions, version 0.5.9 is the way to go. Those using earlier iterations should stick to the 0.4.x series.

Answer №3

Fixing the issue by downgrading to version "winston-elasticsearch": "0.7.0".

According to the documentation:

For compatibility with Winston 3.x and Elasticsearch 6.0 onwards, use version 0.7.0. For Elasticsearch 6.0 and later, use version 0.6.0. For Elasticsearch 5.0 and above, use version 0.5.9. For older versions, stick to the 0.4.x series.

source: https://www.npmjs.com/package/winston-elasticsearch

Answer №4

There is currently an ongoing unresolved issue related to this specific matter.

In the interim, you have the option to execute

npm i --save <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84f3edeaf7f0ebeaa9e1e8e5f7f0ede7f7e1e5f6e7ecc4b4aab3aab5b6">[email protected]</a>
.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Problem encountered with a selection menu

I'm experiencing some trouble with the dropdown menu. Whenever I try to move the mouse to access the dropdown menu, it seems unresponsive. I attempted adjusting the padding on a line of code but ended up moving the entire line instead. Here is the cod ...

Ways to conceal a child div element without using any specific ID reference

I encountered an issue where I need to conceal all divs within a parent div except the first one. The challenge is that these divs do not possess any unique identifiers. Is there a way to achieve this task using CSS or pure JavaScript? <div role="list ...

A TypeError was encountered: Attempting to read the 'substr' property of an undefined variable

Recently, I encountered an issue while working on a script with jquery.min.js version 1.4. The problem arose when I had to upgrade the script to version 1.9.1. Uncaught TypeError: Can not read property 'substr' of undefined. I need assistance i ...

What are the steps to implement timer control in Ajax using JavaScript?

Hello, I have been trying to establish communication with the server through my application. To achieve this, I made a call to the webservice using AJAX. Now, I am looking to incorporate a time interval in AJAX. Can anyone kindly provide guidance on how ...

What is the best way to import information from a CSV or Excel file directly into my program?

I am currently using puppeteer for automating a form submission process. I am looking to extract data directly from a csv file and input it into the form. Can someone guide me on how to achieve this? The CSV file contains the following information: Fir ...

Launching the webpage with Next.js version 13

Hey there! I'm currently working on implementing a loading screen for my website to enhance the user experience. Since it's quite a large site, I believe a loading screen would be beneficial. However, I'm having trouble getting it to work on ...

Preventing typing during onKeyDown event in React/JavaScript and other languages

One of the reasons why I opt to use onKeyDown is because the language for typing is Korean. With multiple inputs on the page, my aim is to prevent users from typing more than 20 bytes. //this function calculates the byte length const getByteLength = (s,b ...

How can I implement custom code to run in all Ajax requests in Ext JS without having to manually insert it into each individual request?

When a user is logged in, ajax requests function properly. However, if the session becomes invalidated, the ajax returns a login screen and displays it as ajax content. I am wondering if it is feasible to incorporate custom code in Ext JS that would be e ...

Varied elevations dependent on specific screen dimensions

There seems to be a minor issue with the height of the portfolio container divs at specific window widths. The problematic widths range from 1025 to 1041 and from 768 to 784. To visualize this, try resizing your browser window to these dimensions on the fo ...

`problem encountered when attempting to sanitize HTML through the npm package known as "sanitize-html"`

After researching the documentation, I attempted to use this code snippet: const dirty = '<div>Content</div>'; const clean = sanitizeHtml(dirty); The desired result of 'clean' should be "Content", however it seems that &apo ...

Automatically customizable CSS border thickness

Consider the following example of a div element: <div style="height: 10%; width: 20%; border: 1px solid black"> Div Content </div> The div above has its height and width specified in percentages. I would like the border width to adjust a ...

Issue encountered: Inoperable binding when employing ko.mapping with two distinct models

I've been struggling to implement a drop-down select in conjunction with a table on a page using knockout bindings. The issue arises when I try to use the mapping options in the knockout binding plugin – either the drop-down or the table behaves inc ...

Utilize moment.js to convert an epoch date into a designated time zone

I've spent countless hours searching for a resolution to the issue with moment.js and its inability to accurately display the correct date for a given local time zone. Let me explain my predicament: The flight API I'm utilizing provides me w ...

Why am I seeing the error message "SyntaxError: Cannot use import statement outside a module"?

I am encountering an issue while using React JS with SSR (express). When I try to start the server, I receive the following error message: C:\PROPJECTS\SSR+1\plusone\node_modules\antd\es\empty\style\css.js:1 imp ...

Refresh a dynamically loaded webpage following an update

Trying to grasp the concept of reloading a dynamic page loaded with AJAX after a record is updated. Here's the jquery script on the page: <script type="text/javascript> function showUser(str) { if (str == "") { $("#txtHint").empty() ...

The Node.js application gracefully exited with code 0 with Forever

Running a Node.js Express app on CentOs 6.5 using the root account: root@vps [/home/test/node]# npm start app.js > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aedacbdddaee9e809e809f">[email protected]</a> s ...

Is there a proper method in AngularJS for factories to return objects?

I am facing an issue in retrieving POST data in an Angular.js project. This is the factory I am using: angular.module('mtApp').factory('getKey', function($http) { return { getData: function(data) { var key=&apos ...

restore the HTML element to its initial position after being moved

I am utilizing document.getElementById('Droping1').style['-webkit-transform'] = translate(0px,'+Ground+'px)'; in order to relocate an HTML element. How can I return it to its original position for reusability without t ...

Steps for filling an HTML table within a dynamically loaded DIV

I have a container in my HTML page where I dynamically load other pages using the jQuery.load() function. One of the pages requires me to populate a table from the database just after/before it loads. How can I trigger a JavaScript function to execute righ ...

Why does the selectedItems in the AngularJS grid keep coming back as undefined?

Is there a specific reason why the angularjs grid in my sample isn't displaying the selectedItems properly? Every time I attempt to reference the selectedItems, it returns "undefined." I have tested this in both Chrome and IE with identical outcomes. ...