title: RangeError: Maximum call stack size exceeded in node_modules -> elasticsearch
body: <p>While trying to write a function to deploy on Firebase Function, I wrote this code:</p>
  
  <pre><code>'use strict';
  const elasticsearch = require('elasticsearch');
  const firebaseAdmin = require('firebase-admin');
  const functions = require('firebase-functions');
  const Promise  = require('promise');
  
  const config = {
      firebaseUrl: FIREBASE_URL,
      elasticSearchUrl: ELASTICSEARCH_URL
  };
  // configure firebase
  const serviceAccount = require("./serviceAccountKey.json");
  firebaseAdmin.initializeApp({
    credential: firebaseAdmin.credential.cert(serviceAccount),
    databaseURL: config.firebaseUrl
  });
  const database = firebaseAdmin.database();
  const client =  new elasticsearch.Client({
      host: config.elasticSearchUrl
  });
  exports.indexentry = functions.database.ref('/posts/{postid}/text').onWrite(event =&gt; {
    let data = event.data.val();
    let post_id = event.params.postid;
  
    let indexData = {
          index: "firebase",
          type: "posts",
          id: post_id,
          body: data
      }
  
    return client.index(indexData).then(response =&gt; {
      console.log('Response: ');
    });
  });
  </code></pre>
  
  <p>I get an error: </p>
  
  <p>Error: Error occurred while parsing your function triggers.</p>
  
  <pre><code>RangeError: Maximum call stack size exceeded
      at Function.EventEmitter.listenerCount (events.js:440:38)
      at Log.listenerCount (C:\Users\Dell\AppData\Local\Temp\fbfn_10872H41uMk66c53o\node_modules\elasticsearch\src\lib\log.js:68:25)
      at Function.EventEmitter.listenerCount (events.js:442:20)
      at Log.listenerCount (C:\Users\Dell\AppData\Local\Temp\fbfn_10872H41uMk66c53o\node_modules\elasticsearch\src\lib\log.js:68:25)
      at Function.EventEmitter.listenerCount (events.js:442:20)
      at Log.listenerCount (C:\Users\Dell\AppData\Local\Temp\fbfn_10872H41uMk66c53o\node_modules\elasticsearch\src\lib\log.js:68:25)
      at Function.EventEmitter.listenerCount (events.js:442:20)
      at Log.listenerCount (C:\Users\Dell\AppData\Local\Temp\fbfn_10872H41uMk66c53o\node_modules\elasticsearch\src\lib\log.js:68:25)
      at Function.EventEmitter.listenerCount (events.js:442:20)
      at Log.listenerCount (C:\Users\Dell\AppData\Local\Temp\fbfn_10872H41uMk66c53o\node_modules\elasticsearch\src\lib\log.js:68:25)
      at Function.EventEmitter.listenerCount (events.js:442:20)
      at Log.listenerCount (C:\Users\Dell\AppData\Local\Temp\fbfn_10872H41uMk66c53o\node_modules\elasticsearch\src\lib\log.js:68:25)
      at Function.EventEmitter.listenerCount (events.js:442:20)
      at Log.listenerCount (C:\Users\Dell\AppData\Local\Temp\fbfn_10872H41uMk66c53o\node_modules\elasticsearch\src\lib\log.js:68:25)
      at Function.EventEmitter.listenerCount (events.js:442:20)
      at Log.listenerCount (C:\Users\Dell\AppData\Local\Temp\fbfn_10872H41uMk66c53o\node_modules\elasticsearch\src\lib\log.js:68:25)
  </code></pre>
  
  <p>In one of the comments on Github I found a fix:
  It asked me to add this anywhere in my code:</p>
  
  <pre><code>var EventEmitter = require('events').EventEmitter;
  var Log = require('./node_modules/elasticsearch/src/lib/log');
  Log.prototype.listenerCount = EventEmitter.prototype.listenerCount;
  </code></pre>
  
  <p>Now I get an error: </p>
  
  <pre><code>Error: unknown error at respond (/user_code/node_modules/elasticsearch/src/lib/transport.js:234:15) at checkRespForFailure (/user_code/node_modules/elasticsearch/src/lib/transport.js:200:7) at HttpConnector.&lt;anonymous&gt; (/user_code/node_modules/elasticsearch/src/lib/connectors/http.js:155:7) at IncomingMessage.wrapper (/user_code/node_modules/elasticsearch/node_modules/lodash/index.js:3095:19) at emitNone (events.js:91:20) at IncomingMessage.emit (events.js:185:7) at endReadableNT (_stream_readable.js:974:12) at _combinedTickCallback (internal/process/next_tick.js:74:11) at process._tickDomainCallback (internal/process/next_tick.js:122:9)
   Error: unknown error
      at respond (/user_code/node_modules/elasticsearch/src/lib/transport.js:234:15)
      at checkRespForFailure (/user_code/node_modules/elasticsearch/src/lib/transport.js:200:7)
      at HttpConnector.&lt;anonymous&gt; (/user_code/node_modules/elasticsearch/src/lib/connectors/http.js:155:7)
      at IncomingMessage.wrapper (/user_code/node_modules/elasticsearch/node_modules/lodash/index.js:3095:19)
      at emitNone (events.js:91:20)
      at IncomingMessage.emit (events.js:185:7)
      at endReadableNT (_stream_readable.js:974:12)
      at _combinedTickCallback (internal/process/next_tick.js:74:11)
      at process._tickDomainCallback (internal/process/next_tick.js:122:9)
  </code></pre>
  
  <p>How to fix this?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I updated elasticsearch as suggested in the first answer. Now I get the error:</p>
  
  <pre><code> Error: [mapper_parsing_exception] failed to parse
          at respond (/user_code/node_modules/elasticsearch/src/lib/transport.js:307:15)
          at checkRespForFailure (/user_code/node_modules/elasticsearch/src/lib/transport.js:266:7)
          at HttpConnector.&lt;anonymous&gt; (/user_code/node_modules/elasticsearch/src/lib/connectors/http.js:159:7)
          at IncomingMessage.bound (/user_code/node_modules/elasticsearch/node_modules/lodash/dist/lodash.js:729:21)
          at emitNone (events.js:91:20)
          at IncomingMessage.emit (events.js:185:7)
          at endReadableNT (_stream_readable.js:974:12)
          at _combinedTickCallback (internal/process/next_tick.js:74:11)
          at process._tickDomainCallback (internal/process/next_tick.js:122:9)
  </code></pre>