未捕获的TypeError:无法读取未定义的属性“Client”

时间:2018-02-16 20:37:53

标签: javascript elasticsearch-5

我收到一个无法解决的错误。帮助赞赏。 见下面的图片。

JS code

JS Error

谢谢!

从调试中添加了信息: Cannot read property 'Client' of undefined" stack : "TypeError: Cannot read property 'Client' of undefined↵ at eval (eval at <anonymous> (http://192.168.10.151:8000/scripts/main.js:7:36), <anonymous>:1:15)↵ at http://192.168.10.151:8000/scripts/main.js:7:36↵ at Object.execCb (http://192.168.10.151:8000/scripts/require.js:1650:33)↵ at Module.check (http://192.168.10.151:8000/scripts/require.js:866:51)↵ at Module.<anonymous> (http://192.168.10.151:8000/scripts/require.js:1113:34)↵ at http://192.168.10.151:8000/scripts/require.js:132:23↵ at http://192.168.10.151:8000/scripts/require.js:1156:21↵ at each (http://192.168.10.151:8000/scripts/require.js:57:31)↵ at Module.emit (http://192.168.10.151:8000/scripts/require.js:1155:17)↵ at Module.check (http://192.168.10.151:8000/scripts/require.js:917:30)

1 个答案:

答案 0 :(得分:1)

在使用@SteveR建议的调试器后,我终于找到了一个提示,导致我使用elastiseach.js和以下内容:

    // In order to help people who were accidentally upgraded to this ES client,
    // throw an error when they try to instanciate the exported function.
    // previous "elasticsearch" module -> https://github.com/ncb000gt/node-es
    function es() {
      throw new Error('Looks like you are expecting the previous "elasticsearch" module. '
    +
        'It is now the "es" module. To create a client with this module use' +
        '`new es.Client(params)`.');
    }

    es.Client = __webpack_require__(1);
    es.ConnectionPool = __webpack_require__(33);
    es.Transport = __webpack_require__(2);
    es.errors = __webpack_require__(17);

    module.exports = es;

相应修复我的代码:

define(['scripts/d3.v3', 'scripts/elasticsearch'], function (d3, es) { "use strict"; var client = new elasticsearch.Client({ host: 'http://192.168.10.151:9200' }); // your code }