angular 6 ERROR ReferenceError:“进程未定义"使用弹性搜索 js [英] angular 6 ERROR ReferenceError: "process is not defined" with elasticsearch js

查看:25
本文介绍了angular 6 ERROR ReferenceError:“进程未定义"使用弹性搜索 js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此之前,我阅读了:

问题 1 关于流程未定义

关于流程的问题 2 未定义

angular 5 问题

浏览器构建信息

而且所提供的信息都没有帮助.我正在使用 Angular 6,我想使用 elasticsearch js 向 elasticsearch 发送查询.我像这样安装了弹性搜索、弹性类型和弹性浏览器:

npm install elasticsearchnpm install @types/elasticsearchnpm 安装弹性搜索浏览器

我尝试使用 --save、--save-dev 和不使用进行安装,但无济于事.

然后我用 angular cli 创建了一个新项目:

import { Component } from '@angular/core';从elasticsearch"导入{客户端};@成分({选择器:'app-root',模板:`<script src="/node_modules/elasticsearch/src/elasticsearch.js"></script><div class="容器"><div class="row"><button type="" (click)="onSendElastic()">点击我!</button>

</div>`,styleUrls: ['./app.component.css']})导出类 AppComponent {elClient:客户端onSendElastic(){console.log('点击发送 eltic');this.connect()让 res = this.elSearch()console.log(`res: ${res}`);}连接(){console.log('开始连接...');this.elClient = 新客户端({主机:"http://elasticIp:9200",日志:跟踪"})this.elClient.ping({请求超时:2000},(错误)=>{如果(错误){console.log('错误');}别的{console.log('一切正常');}})}elSearch(){console.log('开始搜索...');返回 this.elClient.search({索引:elastic_index",类型:文档",身体:{询问":{学期":{字段1":真"}}}})}}

我添加了 <script> 标签,因为我发现的一些答案暗示了这一点,但没有帮助.

格式取自:https://www.npmjs.com/package/elasticsearch.当我启动项目时,通过运行 ng startnpm start,当我按下按钮时,我得到:

<块引用>

点击发送eltic;开始连接...错误参考错误:进程没有定义"addOutputhttp://localhost:4200/vendor.js:100911:7Loghttp://localhost:4200/vendor.js:100749:5Transporthttp://localhost:4200/vendor.js:101610:27EsApiClienthttp://localhost:4200/vendor.js:99098:22Clienthttp://localhost:4200/vendor.js:99141:10connecthttp://localhost:4200/main.js:104:25onSendElastichttp://localhost:4200/main.js:98:9View_AppComponent_0ng:///AppModule/AppComponent.ngfactory.js:14:23handleEventhttp://localhost:4200/vendor.js:39410:16callWithDebugContexthttp://localhost:4200/vendor.js:40503:22debugHandleEventhttp://localhost:4200/vendor.js:40206:12dispatchEventhttp://localhost:4200/vendor.js:36869:16renderEventHandlerClosurehttp://localhost:4200/vendor.js:37313:38decoratePreventDefaulthttp://localhost:4200/vendor.js:47314Task:http://localhost:4200//localhost:4200/polyfills.js:2743:17onInvokeTaskhttp://localhost:4200/vendor.js:33108:24invokeTaskhttp://localhost:4200/polyfills.js:2742:17runTaskhttp://localhost:4200/polyfills.js:2510:28invokeTaskhttp://localhost:4200/polyfills.js:2818:24invokeTaskhttp://localhost:4200/polyfills.js:3862:9globalZoneAwareCallbackhttp://localhost:4200/polyfills.js:3888:17

我找到了使用 elasticsearch 浏览器的参考,但安装它似乎没有任何作用.浏览器页面中的信息引用了 angularjs,而不是 angular 2,所以我被卡住了.

为什么会发生这个错误?如何解决?

解决方案

我们在 此线程 为我们工作:

特别是:

 npm i -S process,然后将其添加到 polyfill.ts:从进程"导入 * 作为进程;窗口['进程'] = 进程;

Before everything, I read:

question 1 regarding process is not defined

question 2 regarding process is not defined

angular 5 question

browser build info

And none of the presented info helped. I'm using Angular 6 and I want to send query to elasticsearch, using elasticsearch js. I installed elasticsearch, elastic types and elastic browser like so:

npm install elasticsearch
npm install @types/elasticsearch
npm install elasticsearch-browser

I tried installing with --save, with --save-dev and without, to no avail.

Then I created a new project with angular cli:

import { Component } from '@angular/core';
import { Client } from "elasticsearch";

@Component({
  selector: 'app-root',
  template: `
<script src="/node_modules/elasticsearch/src/elasticsearch.js"></script>
  <div class="container">
  <div class="row">
      <button type="" (click)="onSendElastic()">Click Me!</button>
  </div>
</div>`,
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  elClient: Client

  onSendElastic(){
    console.log('clicked on send elstic');
    this.connect()
    let res = this.elSearch()
    console.log(`res: ${res}`);

  }

  connect(){
    console.log('start connect...');

    this.elClient = new Client({
      host:"http://elasticIp:9200",
      log:"trace"
    })
    this.elClient.ping({
      requestTimeout:2000
    },(err)=>{
      if(err){
        console.log('err');
      }
      else{
        console.log('everything is ok');

      }
    })
  }

  elSearch(){
    console.log('start search...');

    return this.elClient.search({
      index:"elastic_index",
      type:"doc",
      body:{
        "query":{
          "term":{
            "field1":"true"
          }
        }
      }
    })
  }
}

I added the <script> tag because some answers that I found suggested this, but it didn't helped.

The format of is taken from: https://www.npmjs.com/package/elasticsearch. When I start the project, by running ng start or npm start, When I press the button I get:

clicked on send elstic; start connect... ERROR ReferenceError: "process is not defined" addOutputhttp://localhost:4200/vendor.js:100911:7Loghttp://localhost:4200/vendor.js:100749:5Transporthttp://localhost:4200/vendor.js:101610:27EsApiClienthttp://localhost:4200/vendor.js:99098:22Clienthttp://localhost:4200/vendor.js:99141:10connecthttp://localhost:4200/main.js:104:25onSendElastichttp://localhost:4200/main.js:98:9View_AppComponent_0ng:///AppModule/AppComponent.ngfactory.js:14:23handleEventhttp://localhost:4200/vendor.js:39410:16callWithDebugContexthttp://localhost:4200/vendor.js:40503:22debugHandleEventhttp://localhost:4200/vendor.js:40206:12dispatchEventhttp://localhost:4200/vendor.js:36869:16renderEventHandlerClosurehttp://localhost:4200/vendor.js:37313:38decoratePreventDefaulthttp://localhost:4200/vendor.js:47314:36invokeTaskhttp://localhost:4200/polyfills.js:2743:17onInvokeTaskhttp://localhost:4200/vendor.js:33108:24invokeTaskhttp://localhost:4200/polyfills.js:2742:17runTaskhttp://localhost:4200/polyfills.js:2510:28invokeTaskhttp://localhost:4200/polyfills.js:2818:24invokeTaskhttp://localhost:4200/polyfills.js:3862:9globalZoneAwareCallbackhttp://localhost:4200/polyfills.js:3888:17

I found a reference to using elasticsearch browser, but installing it dosn't seem to do anything. The info in the browser-bould page refrences angularjs, not angular 2, so I'm stuck.

Why this error is happening? How to solve it?

解决方案

We found that the last solution in this thread worked for us:

Specifically:

 npm i -S process, then add this to polyfill.ts:
 import * as process from 'process';
 window['process'] = process;

这篇关于angular 6 ERROR ReferenceError:“进程未定义"使用弹性搜索 js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆