question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

🐛 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:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
delvedorcommented, Nov 24, 2020

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.

2reactions
halmoscommented, Apr 23, 2021

Just to a comment to vote in favor of re-opening this issue and supporting browser applications. It is certainly possible to have a secure ES instance without the need of a proxy. In our case we use AWS’s Elasticsearch service along with AWS’s Cognito and IAM authentication to grant the client restricted access only to verified users.

In any case, It seems to me that the SDK should not be opinionated about how to secure the server.

It should also be noted that the legacy sdk did support browser environments.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read Property 'split' of Undefined in JS
The "Cannot read property 'split' of undefined" error occurs when trying to call the `split()` method on a variable that stores an `undefined`...
Read more >
Cannot Read Property 'split' of Undefined - freeCodeCamp
it will throw the TypeError: Cannot read property 'split' of undefined error. The split method. When split is called on a string, it...
Read more >
How to prevent cannot read property split of ... - Meticulous
This error is a TypeError , and it occurs when calling a method, operand, or argument on the wrong data type, or when...
Read more >
Cannot read property 'split' of undefined in discord and nodejs ...
"TypeError: Cannot read property 'split' of undefined" basically means that "The value that .split() was called on does not have a .split() ...
Read more >
How to Prevent cannot read property split of ... - Gopi Gorantala
let data = undefined; console.log(data.split(','); // Uncaught TypeError: Cannot read properties of undefined (reading 'split').
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found