TypeError: Cannot read property 'split' of undefined in node_modules/@elastic/elasticsearch/index.js:7
Steps to reproduce the behavior:
npx create-react-app test-appcd test-appnpm install @elastic/elasticsearch// ./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 startTypeError: Cannot read property 'split' of undefined
(anonymous function)
node_modules/@elastic/elasticsearch/index.js:7
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')
the module should be required without error
I did console.log(process.version.node); in node_modules/@elastic/elasticsearch/index.js. It looks to me that process.versions.node is undefined.
@elastic/elasticsearch version: 7.9.1Sorry, 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?