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

The Firebase 'not-in' operator is malfunctioning

Within my database, there is a document located at: https://i.stack.imgur.com/OTZpd.png I am attempting to query the number of messages documents where the user's ID does not appear in the "read_by" array. This is the code I am currently using: const ...

Designing a Model and Service Structure for a NodeJS REST API

In my current project, I am developing a medium-scale application using Express and MariaDB/Cassandra for the back-end system. My approach is to implement the Model Service Controller pattern. Initially, I focused on having thin Controllers and robust Mod ...

Only display PHP page content if accessed through an AJAX request, not through directly typing the URL into the address bar

Is there a way to verify if a PHP page has been accessed via an Ajax request? I'm working on a page that displays a form for updating some database data (update.php), but I only want it to be accessible if it is called by a specific page named "change ...

Adding scripts to a PartialView in MVC using Jquery's append function

My issue is with a JavaScript function that appends a PartialView into a div. Everything seems to work correctly, except for the fact that the PartialView contains some scripts enclosed within <script></script> tags. As a result, when these dyn ...

Tips on implementing a Javascript function triggered by a user's click within the video player frame

<script> function greet() { alert("hello"); } </script> <iframe width="100%" height="315" src="https://www.youtube.com/embed/AGM0ibP1MRc" onclick="greet()"></iframe> .Kindly assist me, please. ...

Utilizing iOS Local Storage for Efficient Form Submission Handling

I feel like my brain is on the verge of exploding. I just can't seem to get this to work as intended, and I'm struggling to pinpoint the issue. Currently, I have a form that needs to be processed using AJAX. Before proceeding with that, I want ...

Navigating with Anchors, Styling and jQuery

Firstly: Apologies in advance for any language errors as English is not my native tongue. :) The Scenario Here's the deal: I'm attempting to create a single button that, when clicked by the user, automatically scrolls down to the next DIV. Each ...

Modify MUI's ListItemText component by targeting a specific span to implement customized styles using the useStyle hook

It's quite perplexing that although this is a straightforward task in regular CSS, it must be accomplished through MUI's useStyles for some peculiar reason. Essentially, I possess a ListItem containing a ListItemText. It appears as follows: cons ...

Experiencing a hiccup in React while attempting to play an mp3 file

My project includes the following code snippet, with an example mp3 file and npm package: https://www.npmjs.com/package/react-sound import React from 'react'; import Sound from 'react-sound'; class CustomSound extends React.Component ...

When using Ajax in Jquery and expecting data of type JSON, the response always seems

Looking to create a basic jQuery Ajax script that checks a user's discount code when the "Check Discount Code" button is clicked? Check out this prototype: <script> jQuery(function($) { $("#btn-check-discount").click(function() { c ...

Is it possible to retrieve the parent object?

My code snippet is as follows, and I'm struggling to access the data object from within the innerFn function. Is there a way to accomplish this? export default { data: { a: "a", b: "b" }, fn: { innerFn: () => co ...

The serialize() method in Ajax is not capturing all the data fields from an HTML form

Attempting to use the jQuery get() method to send form data from my website, I encountered an issue where only a few of the field data were actually transmitted to the server upon form submission. The Form: <form class="form-horizontal" id="addpost" ...

Searching with Elasticsearch can be done using either the "or" operator or

I need help writing a query to search for products in two columns: category1 and category2. I am using the elastic search PHP client and have attempted to use the match should query, but it is providing incorrect results due to substring matches. Instead, ...

What is the process of connecting two models in Mongoose?

In this scenario, we have two models - ProductModel and CategoryModel. The goal here is to establish a connection between creating a product (ProductModel) and assigning it to a category. The issue arises when the category field is not getting filled in t ...

Clear session data when logging out from a dropdown list

I have a header that appears on several of my web pages. It contains a dropdown menu that allows users to log out by selecting the "Logout" option. When a user clicks on "Logout", I want to destroy the session variables associated with their session. Is t ...

Currently in the process of developing an electron application, I encountered an Uncaught Exception error stating: "TypeError: $.ajax is not

I'm currently working on an electron app that interacts with an API endpoint and displays the response on the page. Due to electron's separation of main process and renderer process, I'm using a preload script to facilitate communication bet ...

Is there a way to verify if a FormData file has no content?

Currently working on an AJAX form where users can choose a background color or upload a background image. The aim is to have the bgColor field ignored if a file is specified for bgImg. <label>Color: <input type="color" name="bgColor" value="#0000 ...

Using AngularJS to create a select dropdown menu with nested objects as the options

Currently, I am working on developing an AngularJS application with a complex data structure. The data source consists of an array of individuals with their languages and skill levels. My goal is to be able to filter these individuals based on language sk ...

What is the best way to access the inner html of every cell within a table row that I have selected?

I want to implement a feature on my website where users can click a "save" button on a specific row in a table and save the entire row's innerHtml onto another page as their favorite hiking trails. I've been trying to achieve this by adding clic ...

Issues arise when attempting to alter the background image using jQuery without browserSync being activated

I am facing an issue with my slider that uses background-images and BrowserSync. The slider works fine when BrowserSync is running, but without it, the animations work properly but the .slide background image does not appear at all. Can someone help me ide ...