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

时间:2017-06-14 09:22:55

标签: elasticsearch

当弹性搜索与Vue.js集成时,我遇到了运行时错误,错误未捕获TypeError:无法在eval读取未定义的属性'prototype'(eval at(app.js:1173),:4990:31)。所有浏览器都会出现此问题

elastic_search.js
var es = require('elasticsearch')
var port = 9200
var protocol = 'http'
var hosturl = [ '127.0.0.1']
var hosts = hosturl.map (function(host) {
  return{
    protocol : protocol,
    host : host,
    port : port
  }
})

var client = new es.Client({
  hosts: hosts
})

export function search () {
  alert('hell1')
  return client.search({
    index: 'logstash-2017.06.07',
    type: 'logs',
    body: {
      query: {
        match_all: {}
      }
    }
  }).then(function (resp) {
    return resp.hits.hits
  }, function (err) {
    console.trace(err.message)
  })
}

main.js
import Vue from 'vue'
import App from './App'
import router from './router'
Vue.use(require('vue-resource'))
import {search} from './elastic_search.js'
Vue.config.productionTip = false

/* eslint-disable no-new */
var handler = new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App },
  methods: {
    search: function () {
     search().then(function (res) {
        alert(res)
      })
     }
    }
  })
handler.search()

1 个答案:

答案 0 :(得分:0)

在这种情况下, 你必须在弹性搜索包本身之前安装弹性搜索的类型定义。

我是一名角色2开发人员,并且在角度2或4上有解决此问题的工作解决方案。

如果已经这样做,请卸载所有弹性搜索包...使用类似..

之类的命令
npm uninstall elasticsearch
npm uninstall -g elasticsearch
npm uninstall -g --save-dev elasticsearch
npm uninstall @types/elasticsearch

现在使用angular-cli在项目中安装弹性搜索包的类型定义

npm install @types/elasticsearch

现在安装弹性搜索包

npm install elasticsearch

希望你能与之相关。

相关问题