2017-06-24 48 views
2

在试图写一个函数,在火力地堡功能部署,我写了这个代码:的RangeError:最大调用堆栈大小node_modules突破 - > elasticsearch

'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 => { 
    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 => { 
    console.log('Response: '); 
    }); 
}); 

我得到一个错误:

错误:解析函数触发器时发生错误。

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) 

在Github上的意见之一,我找到了解决: 这让我在我的代码添加此的任何地方:

var EventEmitter = require('events').EventEmitter; 
var Log = require('./node_modules/elasticsearch/src/lib/log'); 
Log.prototype.listenerCount = EventEmitter.prototype.listenerCount; 

现在,我得到一个错误:

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.<anonymous> (/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.<anonymous> (/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) 

如何解决这个问题?

编辑

我更新elasticsearch作为第一个答案建议。现在,我得到的错误:

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.<anonymous> (/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) 

回答

1
  1. 确保您使用的是最新弹性搜索的版本:npm install elasticsearch。在您的package.json文件中添加正确的依赖项,它应该是最近版本的弹性搜索,或者使用commad,npm install [email protected]或任何其他版本。
  2. 您不需要实际覆盖Log.prototype.listenerCount,elasticsearch已经为您在内部为您执行此操作(因此,调用堆栈递归)。因此,删除此行:

Log.prototype.listenerCount = EventEmitter.prototype

此外,虽然这是无关您的问题...它是多余的,包括你需要的路径./node_modules。节点有一个内置的模块搜索机制,并为你做这个。

+0

请参阅编辑部分。新的错误和我一样无知。 –

+0

你用什么版本的节点? – hulkish

+0

节点版本6.10.0和npm版本3.10.10 –

相关问题