Open brabeji opened 8 months ago
The error comes from here: https://github.com/oven-sh/bun/blob/837cbd60d5ffc5d1faf2131bbd8d968217bab2ff/src/js/thirdparty/undici.js#L268-L272
A workaround is to use the HttpConnection
transporter:
-import { Client as ElasticClient } from '@elastic/elasticsearch'; // 8.11.0
+import { Client as ElasticClient, HttpConnection } from '@elastic/elasticsearch'; // 8.11.0
const elasticClient = new ElasticClient({
node: 'http://127.0.0.1:9200',
+ Connection: HttpConnection,
});
await elasticClient.indices.create({ index: 'foo' });
// Wrap the error to get a clean stack trace
539 | const wrappedError = error.name === 'TimeoutError'
540 | ? new errors_1.TimeoutError(error.message, result, errorOptions)
541 | : new errors_1.ConnectionError(error.message, result, errorOptions);
542 | this[symbols_1.kDiagnostic].emit('response', wrappedError, result);
543 | throw wrappedError;
^
ConnectionError: Not implemented in bun
at /home/[userName]/Desktop/project/node_modules/.pnpm/@elastic+transport@8.4.0/node_modules/@elastic/transport/lib/Transport.js:543:20
at asyncFunctionResume (native:1:1)
at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native:1:1)
at promiseReactionJob (native:1:1)
at processTicksAndRejections (native:1:1)
Similar issue when using the solr-client package.
177 | class Client extends Dispatcher {
178 | constructor() {
179 | super(...arguments);
180 | }
181 | request() {
^
error: Not implemented in bun
at request (undici:181:19)
at /Users/<redacted>/node_modules/solr-client/dist/lib/solr.js:154:32
at doRequest (/Users/<redacted>/node_modules/solr-client/dist/lib/solr.js:129:21)
at doQuery (/Users/<redacted>/node_modules/solr-client/dist/lib/solr.js:407:19)
Which correlates to this source code: https://github.com/lbdremy/solr-node-client/blob/c1a2f2a3ec233a19f84b061eb01ff4ae718d14ef/lib/solr.ts#L200
If anyone knows of another Solr client package that is bun-compatible already, please let me know.
Similar issue when using https://github.com/pinojs/pino-elasticsearch package.
This will work:
import { HttpConnection } from '@elastic/elasticsearch'
import pino from 'pino'
import pinoElastic from 'pino-elasticsearch'
const streamToElastic = pinoElastic({
index: 'logs',
node: 'http://localhost:9200',
flushBytes: 100,
auth: {
username: 'elastic',
password: 'xxxxxx',
},
Connection: HttpConnection,
})
streamToElastic.on('unknown', (event) => console.log(event))
streamToElastic.on('error', (error) => {
console.error('Elasticsearch client error:', error)
})
// Capture errors returned from Elasticsearch, "it will be called every time a document can't be indexed".
streamToElastic.on('insertError', (error) => {
console.error('Elasticsearch server error:', error)
})
const pinoOptions = {}
const streams = [{ stream: process.stdout }, { stream: streamToElastic }]
const logger = pino(pinoOptions, pino.multistream(streams))
logger.info('hello world')
What version of Bun is running?
1.0.20
What platform is your computer?
Darwin 23.1.0 arm64 arm
What steps can reproduce the bug?
Simple usage of ElasticSearch client throws
Not implemented in bun
error:What is the expected behavior?
Client working or different error is thrown.
What do you see instead?
"Not implemented in bun" error is thrown
Additional information
After some tracing, the dismissed task of #1987 seems to be an issue, although I can't find the error message in bun codebase which is weird to me.