gpt4 book ai didi

angular - ./node_modules/@elastic/elasticsearch/lib/Connection.js 中出现错误 找不到模块 : Error: Can't resolve 'http'

转载 作者:行者123 更新时间:2023-12-02 21:18:10 24 4
gpt4 key购买 nike

我正在开发一个 Angular 6 项目,我将服务器上的 Elasticsearch 版本从 6 更新到 7,在更改旧 API 的代码以使用新 API 后,出现了这些错误,有人知道如何解决吗?更正吗?

Angular 应用程序是在 Visual Studio 代码上编写的,elasticsearch 在 Linux 服务器上编写的。

import { Injectable } from '@angular/core';
// import { Clientex } from 'elasticsearch-browser';
import { Client } from '@elastic/elasticsearch';
// import * as elasticsearch from 'elasticsearch-browser';
// import { concatMapTo } from 'rxjs/operators';
// import { stringify } from '@angular/core/src/render3/util';


@Injectable({
providedIn: 'root'
})

export class ElasticsearchService {

private client: Client;
// private clientex: Clientex;

constructor() {
if (!this.client) {
this.connect();
}
}

private connect() {
/*this.client = new Client(
{node: 'http://localhost:9200'}
);*/
this.client = new Client();
}

isAvailable(): Promise<any> {
return this.client.ping({
});
}


// tslint:disable-next-line:member-ordering
private queryalldocs = {
'query': {
'match_all': {}
}
};

getAllDocuments(_index, _type): any {
this.client.search({
index: _index,
body: this.queryalldocs
}, {
ignore: [404]
}, (err, { body, statusCode, headers, warnings }) => {
if (err) { console.log(err); }
});
}

getAllDocumentsByKey(_index, _type, campo, valor) {
const string = 'let match = {' + campo + ':' + valor + '}';
return this.client.search({
index: _index,
type: _type,
body: {
// tslint:disable-next-line:no-shadowed-variable
eval(string) {}
}
});
}

createDocument(value: any) {
// return this.client.index(value);
this.client.create(value);
}

}

错误:

ERROR in ./node_modules/@elastic/elasticsearch/lib/Connection.jsModule not found: Error: Can't resolve 'http' in'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules@elastic\elasticsearch\lib'

ERROR in ./node_modules/@elastic/elasticsearch/lib/Connection.jsModule not found: Error: Can't resolve 'https' in'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules@elastic\elasticsearch\lib'

ERROR in ./node_modules/@elastic/elasticsearch/lib/Transport.js Modulenot found: Error: Can't resolve 'os' in'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules@elastic\elasticsearch\lib'

ERROR in ./node_modules/decompress-response/index.js Module not found:Error: Can't resolve 'stream' in'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules\decompress-response'

ERROR in ./node_modules/@elastic/elasticsearch/lib/Transport.js Modulenot found: Error: Can't resolve 'zlib' in'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules@elastic\elasticsearch\lib'

ERROR in ./node_modules/decompress-response/index.js Module not found:Error: Can't resolve 'zlib' in'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules\decompress-response'

最佳答案

根据elasticsearch文档(https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/5.x/breaking-changes.html),所有浏览器客户端都是通过elasticsearch-browser npm包处理的:

No more browser support, for that will be distributed via another module, @elastic/elasticsearch-browser. This module is intended for Node.js only.

关于angular - ./node_modules/@elastic/elasticsearch/lib/Connection.js 中出现错误 找不到模块 : Error: Can't resolve 'http' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56383445/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com