2017-06-24 3 views
2

、私はこのコードを書いた:例外RangeError:node_modulesに超えて最大コールスタックサイズ - Firebase機能に展開する関数を記述しようとしている間> 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: '); 
    }); 
}); 

私はエラーを取得:

エラー:関数の解析中にエラーが発生しました。 それは私のコードでこれのどこを追加するために私に尋ねた:

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) 
私は修正を見つけたのGithub上のコメントの一つで

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) 

これを修正するには?最初の答えで提案されているように、私はelasticsearch更新

EDIT

npm install 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. あなたは弾性検索の最新バージョンを使用していることを確認してください:今、私はエラーを取得します。 package.jsonファイルに適切な依存関係を追加するには、最近のバージョンの弾性検索であるか、またはcommad npm install [email protected]または他のバージョンを使用する必要があります。
  2. Log.prototype.listenerCountを実際に上書きする必要はありません。elasticsearchは内部的にこれを実行しています(つまり、コールスタックの再帰)。これはあなたの問題とは無関係ですしながら、あなたの必要とパスで./node_modulesを含めることが冗長で...、また

Log.prototype.listenerCount = EventEmitter.prototype

:だから、この行を削除してください。ノードにはすでにモジュール探索メカニズムが組み込まれており、これはuのために実行されます。

+0

編集部分をご覧ください。新しいエラーと私は無名: –

+0

あなたはどのノードのバージョンを使用していますか? – hulkish

+0

ノードバージョン6.10.0とnpmバージョン3.10.10 –

関連する問題