bun
bun copied to clipboard
`@elastic/elasticsearch` - The superclass is not a constructor
What version of Bun is running?
0.4.1
What platform is your computer?
No response
What steps can reproduce the bug?
Should be reproducible without a running ES.
import { Client } from '@elastic/elasticsearch';
export const client = new Client({ node: 'http://localhost:9200' })
What is the expected behavior?
Does not throw exception.
What do you see instead?
[6.98ms] "node_modules.bun" - 15 modules, 8 packages
2 |
3 | const https = require('https')
4 | const http = require('http')
5 | const { URL } = require('url')
6 |
7 | class HttpProxyAgent extends http.Agent {
^
TypeError: The superclass is not a constructor.
at /usr/x/gi/node_modules/hpagent/index.js:7:0
at node_modules.server.bun:7:13092
at /usr/x/gi/node_modules/@elastic/transport/lib/connection/HttpConnection.js:23:26
at node_modules.server.bun:7:13092
at /usr/x/gi/node_modules/@elastic/transport/lib/connection/index.js:25:33
at node_modules.server.bun:7:13092
at /usr/x/gi/node_modules/@elastic/transport/index.js:27:2
at node_modules.server.bun:7:13092
at /usr/x/gi/node_modules/@elastic/elasticsearch/index.js:34:2
at node_modules.server.bun:7:13092
at /usr/x/gi/src/worker.ts:23:0
Additional information
No response
The http.Agent polyfill is not implemented yet, but coming very soon. Stay tuned
I have a same problem with apollographql
17 |
18 | class ReadAfterDestroyedError extends Error {}
19 |
20 | exports.ReadAfterDestroyedError = ReadAfterDestroyedError;
21 |
22 | class ReadStream extends _fs.default.ReadStream {
^
TypeError: The superclass is not a constructor.
at /Users/syd/work/sitak/pureSatek/packages/server/node_modules/@apollographql/graphql-upload-8-fork/node_modules/fs-capacitor/lib/index.js:22:0
at /Users/syd/work/sitak/pureSatek/packages/server/node_modules/@apollographql/graphql-upload-8-fork/lib/processRequest.js:10:4
at /Users/syd/work/sitak/pureSatek/packages/server/node_modules/@apollographql/graphql-upload-8-fork/lib/index.js:10:4
at /Users/syd/work/sitak/pureSatek/packages/server/node_modules/apollo-server-core/dist/processFileUploads.js:9:8
at /Users/syd/work/sitak/pureSatek/packages/server/node_modules/apollo-server-core/dist/processFileUploads.js:12:4
at /Users/syd/work/sitak/pureSatek/packages/server/node_modules/apollo-server-core/dist/index.js:44:4
at /Users/syd/work/sitak/pureSatek/packages/server/node_modules/apollo-server-express/dist/index.js:13:4
at /Users/syd/work/sitak/pureSatek/packages/server/dist/src/index.js:16:6
at bun:main:8:19
I have a same problem with
apollographql22 | class ReadStream extends _fs.default.ReadStream { ^ TypeError: The superclass is not a constructor.
This is a similar problem but with a different module, it's actually more related to #1797 . We should really address that one too.
As for this issue regarding http.Agent, the fix should be in the next release. PR will be up today. Will test @elastic/elasticsearch to make sure it works or if there is something else to fix.
http.Agent doesn't seem to be a problem anymore in canary, but we have a new error:
96 | };
97 | }
98 | else if (this.tls !== null) {
99 | undiciOptions.connect = this.tls;
100 | }
101 | this.pool = new undici_1.Pool(this.url.toString(), undiciOptions);
^
TypeError: undefined is not a constructor (evaluating 'new undici_1.Pool(this.url.toString(), undiciOptions)')
I'm guessing this has to do with our undici polyfill not having Pool implemented yet. Will have to look into it, though, in order to confirm.
@hemedani
I have a same problem with
apollographql17 | 18 | class ReadAfterDestroyedError extends Error {} 19 | 20 | exports.ReadAfterDestroyedError = ReadAfterDestroyedError; 21 | 22 | class ReadStream extends _fs.default.ReadStream { ^ TypeError: The superclass is not a constructor.
I believe your issue may have been fixed in https://github.com/oven-sh/bun/pull/1798
And @asilvas , I believe this issue is also resolved in https://github.com/oven-sh/bun/commit/5598ea69f23683c593715764ed1a7d75c1092e8e . Let me know if it's still not working for you
Progress!
20 | Object.defineProperty(exports, "__esModule", { value: true });
21 | exports.ProductNotSupportedError = exports.RequestAbortedError = exports.ResponseError = exports.ConfigurationError = exports.DeserializationError = exports.SerializationError = exports.NoLivingConnectionsError = exports.ConnectionError = exports.TimeoutError = exports.ElasticsearchClientError = void 0;
22 | class ElasticsearchClientError extends Error {
23 | constructor(message) {
24 | super(message);
25 | this.name = 'ElasticsearchClientError';
^
ConnectionError: this.pool.request is not a function. (In 'this.pool.request(requestParams)', 'this.pool.request' is undefined)
at /root-path/node_modules/@elastic/transport/lib/errors.js:25:13
Ah darn I thought that was enough. Well we also need to polyfill undici.request (tracking in #1987), which Pool.request could probably just wrap. We'll see if that gets it working
After finishing up on apollographql + elasticsearch, any plans with regards to neo4j ?
Latest progress from canary:
[1.34ms] "node_modules.bun" - 14 modules, 7 packages
20 | var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
21 | Object.defineProperty(exports, "__esModule", { value: true });
22 | exports.lowerCaseHeaders = exports.generateRequestId = void 0;
23 | const tslib_1 = require("tslib");
24 | const debug_1 = tslib_1.__importDefault(require("debug"));
25 | const os_1 = tslib_1.__importDefault(require("os"));
^
TypeError: Cannot export a duplicate name 'machine'. while parsing module "node:os"
at /x/node_modules/@elastic/transport/lib/Transport.js:25:21
at node_modules.server.bun:7:13090
at /x/node_modules/@elastic/transport/index.js:23:6
at node_modules.server.bun:7:13090
at /x/node_modules/@elastic/elasticsearch/index.js:34:2
at node_modules.server.bun:7:13090
at /x/estest.js:1:0
Latest progress from canary:
[1.34ms] "node_modules.bun" - 14 modules, 7 packages 20 | var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0; 21 | Object.defineProperty(exports, "__esModule", { value: true }); 22 | exports.lowerCaseHeaders = exports.generateRequestId = void 0; 23 | const tslib_1 = require("tslib"); 24 | const debug_1 = tslib_1.__importDefault(require("debug")); 25 | const os_1 = tslib_1.__importDefault(require("os")); ^ TypeError: Cannot export a duplicate name 'machine'. while parsing module "node:os" at /x/node_modules/@elastic/transport/lib/Transport.js:25:21 at node_modules.server.bun:7:13090 at /x/node_modules/@elastic/transport/index.js:23:6 at node_modules.server.bun:7:13090 at /x/node_modules/@elastic/elasticsearch/index.js:34:2 at node_modules.server.bun:7:13090 at /x/estest.js:1:0
Once canary rebuilds, please try again
Yep back to the prior state: https://github.com/oven-sh/bun/issues/1749#issuecomment-1431379606
Ok, I created this tiny client https://github.com/samuelgja/elastic-tiny-client based on fetch. Works in, bun nodejs maybe deno? Try, comment, review :) But main purpose was to run it here in bun! Supports basic operations, there is still missing some parts, but can be updated :) Also lost of package size is typing taken from official repo.
The original reproduction doesn't seem to break anymore in bun 0.8 - @asilvas can you confirm?
This is also happening with Next.js 11.
class CustomDocument extends next_document__WEBPACK_IMPORTED_MODULE_1__ {
^
TypeError: The superclass is not a constructor.
at ./pages/_document.js (/Users/tusharshahi/project/website/.next/server/pages/_document.js:186:0)
at __webpack_require__ (/Users/tusharshahi/project/website/.next/server/webpack-runtime.js:33:12)
at __webpack_exec__ (/Users/tusharshahi/project/website/.next/server/pages/_document.js:196:58)
at /Users/tusharshahi/project/website/.next/server/pages/_document.js:197:27
at /Users/tusharshahi/project/website/.next/server/pages/_document.js:198:17
at globalThis (/Users/tusharshahi/project/website/.next/server/pages/_document.js:200:3)
at require (:1:20)
at requirePage (/Users/tusharshahi/project/website/node_modules/next/dist/server/require.js:47:11)
at /Users/tusharshahi/project/website/node_modules/next/dist/server/load-components.js:47:24
at loadComponents (/Users/tusharshahi/project/website/node_modules/next/dist/server/load-components.js:29:30)
at /Users/tusharshahi/project/website/node_modules/next/dist/server/next-server.js:959:35
at findPageComponents (/Users/tusharshahi/project/website/node_modules/next/dist/server/next-server.js:943:29)
at /Users/tusharshahi/project/website/node_modules/next/dist/server/dev/next-dev-server.js:546:19
at processTicksAndRejections (:1:2602)
I am on the latest version.
@birkskyum But what is that ConnectionError: Not implemented in bun
node_modules/@elastic/transport/lib/Transport.js:529:30
at asyncFunctionResume (native)
at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native)
at promiseReactionJob (native)
at processTicksAndRejections (native)
at asyncFunctionResume (native)
at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native)
at promiseReactionJob (native)
at processTicksAndRejections (native)
at new ConnectionError (/node_modules/@elastic/transport/lib/errors.js:54:8)
at /node_modules/@elastic/transport/lib/Transport.js:528:30
at processTicksAndRejections (:61:76)
at asyncFunctionResume (native)
at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native)
at promiseReactionJob (native)
at processTicksAndRejections (native)
Just posting this here incase anyone is trying to get Elastic working with Bun and having unable to verify the first certificate. After lots of digging I found how to make it work with custom CA, since bun does not yet have NODE_EXTRA_CA_CERTS.
import { Client, HttpConnection, type ConnectionOptions } from '@elastic/elasticsearch';
import { type RequestOptions } from 'https';
// Fixes CA issue with Bun
class ExtHttpConnection extends HttpConnection {
constructor(opts: ConnectionOptions) {
super(opts);
const oldMakeRequest = this.makeRequest;
this.makeRequest = (requestOpts: string | RequestOptions | URL) => {
if (typeof requestOpts === 'object') requestOpts.ca = opts.tls?.ca;
return oldMakeRequest(requestOpts);
};
}
}
const client = new Client({
node: 'https://localhost:9200/',
Connection: ExtHttpConnection,
tls: {
ca: await Bun.file('ca.crt').text()
}
});
I'm not exactly sure why on node you can specify tls.ca in the Elastic Client constructor but not Bun, but this fixes it.