Elasticsearch-js: TypeError: Cannot read property 'split' of undefined in node_modules/@elastic/elasticsearch/index.js:7

Created on 5 Nov 2020  路  5Comments  路  Source: elastic/elasticsearch-js

馃悰 Bug Report

TypeError: Cannot read property 'split' of undefined in node_modules/@elastic/elasticsearch/index.js:7

To Reproduce

Steps to reproduce the behavior:

  • npx create-react-app test-app
  • cd test-app
  • npm install @elastic/elasticsearch
  • edit ./src/App.js to require the library
// ./src/App.js

import logo from './logo.svg';
import './App.css';

const { Client } = require('@elastic/elasticsearch')

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.js</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
      </header>
    </div>
  );
}

export default App;
  • npm start
  • error reported int he browser:

TypeError: Cannot read property 'split' of undefined
(anonymous function)
node_modules/@elastic/elasticsearch/index.js:7

  • code snippet in the error:
   4 | 
   5 | 'use strict'
   6 | 
>  7 | const nodeMajor = Number(process.versions.node.split('.')[0])
   8 | 
   9 | const { EventEmitter } = require('events')
  10 | const { URL } = require('url')

Expected behavior

the module should be required without error

Debugging

I did console.log(process.version.node); in node_modules/@elastic/elasticsearch/index.js. It looks to me that process.versions.node is undefined.

Your Environment

  • node version: was v12.18.4 upgraded to v14.15.0 same issue
  • @elastic/elasticsearch version: 7.9.1
  • os: Mac
  • any other relevant information:

All 5 comments

Sorry, I think I am confused. I don't think this library was designed to be used directly in react.js. I believe that value is empty because react is executed client-side.

Reopen issue please, npm modules should work also with client libs such as React or Vue.

Rationale: fast prototypes

npm modules should work also with client libs such as React or Vue.

@vikiival I don't agree, some libraries can work in both environments, others can't.
It's not safe connecting directly to Elasticsearch from the browser, as it will expose you to security risks, hence we do not support it.
You can write a small node.js proxy for sending queries and make the browser communicate with your proxy.

@delvedor I am also having this issue, but exposing an ElasticSearch cluster to the web does not really entail security risks if your indices are protected properly and your infra is properly configured. On the contrary, it allows fast low latency query from the front end when interrogating ES from the browser. Would you please re-open the issue? 馃檱

@andreasanta Even if your cluster is properly configured, and you are using an ES user with very low permissions, an attacker could still send heavy queries and overload the cluster.
Would you ever expose postgres/mongodb to the world?

Was this page helpful?
0 / 5 - 0 ratings