Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the Got library not work with Bun #3150

Closed
drag0n-app opened this issue Jun 1, 2023 · 27 comments
Closed

the Got library not work with Bun #3150

drag0n-app opened this issue Jun 1, 2023 · 27 comments
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@drag0n-app
Copy link

What version of Bun is running?

0.6.5

What platform is your computer?

Darwin 22.1.0 arm64 arm

What steps can reproduce the bug?

import got from 'got';

let response = await got('https://bun.sh/');
console.log(response.statusCode);

What is the expected behavior?

200

What do you see instead?

7 | const ClientRequest = require('./client-request.js');
8 | const IncomingMessage = require('./incoming-message.js');
9 | const auto = require('./auto.js');
10 | const {
11 | HttpOverHttp2,
12 | HttpsOverHttp2
^
TypeError: undefined is not an object (evaluating 'new tls.TLSSocket(new stream.PassThrough)._handle._parentWrap')

Additional information

No response

@drag0n-app drag0n-app added the bug Something isn't working label Jun 1, 2023
@Jarred-Sumner
Copy link
Collaborator

I don’t think it’ll fix this particular issue but small chance it will

Can you try upgrading to v0.6.6?

@drag0n-app
Copy link
Author

v0.6.6 still showing the same error

@Electroid Electroid added the node.js Compatibility with Node.js APIs label Jun 1, 2023
@shuiRong
Copy link

shuiRong commented Jun 17, 2023

same issue same "got"

bun version: 0.6.7

 bun run src/index.ts
[0.21ms] ".env"
1 | 'use strict';
2 | const stream = require('stream');
3 | const tls = require('tls');
4 | 
5 | // Really awesome hack.
6 | const JSStreamSocket = (new tls.TLSSocket(new stream.PassThrough()))._handle._parentWrap.constructor;
                           ^
TypeError: undefined is not an object (evaluating 'new tls.TLSSocket(new stream.PassThrough)._handle._parentWrap')
      at /Users/xxx/Work/site-fetcher/node_modules/http2-wrapper/source/utils/js-stream-socket.js:6:24
      at (eval) (/Users/xxx/Work/site-fetcher/node_modules/http2-wrapper/source/utils/js-stream-socket.js:8:17)
      at /Users/xxxx/Work/site-fetcher/node_modules/http2-wrapper/source/proxies/h1-over-h2.js:5:6
      at (eval) (/Users/xxxx/Work/site-fetcher/node_modules/http2-wrapper/source/proxies/h1-over-h2.js:90:0)
      at /Users/xxxx/Work/site-fetcher/node_modules/http2-wrapper/source/index.js:12:1
      at (eval) (/Users/xxxxx/Work/site-fetcher/node_modules/http2-wrapper/source/index.js:50:0)

@3ldar
Copy link

3ldar commented Jul 5, 2023

It seems the above issue is fixed in canary build 0.6.14 but now it raises another error like the one below:

218 |         this.on('newListener', event => {
219 |             if (event === 'retry' && this.listenerCount('retry') > 0) {
220 |                 throw new Error('A retry listener has been attached already.');

Source to line

The above error still occurs as of v0.8.0

@ajschmidt8
Copy link

ajschmidt8 commented Jul 9, 2023

I'm also experiencing this issue with bun version 0.6.13.

Here's my minimal reproducer:

import got from "got";
await got('https://bun.sh/');

My stack trace is identical to what 3ldar posted:

Full Stack Trace

215 |                 Object.assign(this.options.headers, source.headers);
216 |             }
217 |         });
218 |         this.on('newListener', event => {
219 |             if (event === 'retry' && this.listenerCount('retry') > 0) {
220 |                 throw new Error('A retry listener has been attached already.');
                          ^
error: A retry listener has been attached already.
      at /workspaces/nap-hugo/backend/node_modules/got/dist/source/core/index.js:220:22
      at makeRequest (/workspaces/nap-hugo/backend/node_modules/got/dist/source/as-promise/index.js:107:12)
      at /workspaces/nap-hugo/backend/node_modules/got/dist/source/as-promise/index.js:125:8
      at /workspaces/nap-hugo/backend/node_modules/p-cancelable/index.js:63:3
      at new PCancelable (/workspaces/nap-hugo/backend/node_modules/p-cancelable/index.js:31:18)
      at asPromise (/workspaces/nap-hugo/backend/node_modules/got/dist/source/as-promise/index.js:21:20)
      at lastHandler (/workspaces/nap-hugo/backend/node_modules/got/dist/source/create.js:42:26)
      at iterateHandlers (/workspaces/nap-hugo/backend/node_modules/got/dist/source/create.js:49:18)
44 |             enumerable: true,
45 |             configurable: true,
46 |             writable: true,
47 |             value: void 0
48 |         });
49 |         Error.captureStackTrace(this, this.constructor);
            ^
RequestError: Attempted to assign to readonly property.
 code: "ERR_GOT_REQUEST_ERROR"

      at new RequestError (/workspaces/nap-hugo/backend/node_modules/got/dist/source/core/errors.js:49:8)
      at _beforeError (/workspaces/nap-hugo/backend/node_modules/got/dist/source/core/index.js:310:20)
      at /workspaces/nap-hugo/backend/node_modules/got/dist/source/core/index.js:772:12

From the stack trace details and the nodejs-apis chart linked below, I think it could have something to do with events.on not being implemented in the node:events library yet.

Actually, I'm not sure if my statement above is accurate.

@paperdave
Copy link
Member

image

bun's node:http.IncomingMessage does not allow ovewriting these properties because they are only getters:

image

@muhamed-didovic
Copy link

Hi, version 1.0.2 shows still the same error, any info on when PR could be merged?

@paperdave
Copy link
Member

the pr has failing tests unfortunatly

@gilmillasseau
Copy link

Hey @paperdave I just updated Bun and this is still happening #6427, do you know if this will be picked up soon? I also tried with the latest version "got": "13.0.0",

@eliellis
Copy link

eliellis commented Dec 6, 2023

Just ran into this one today while experimenting with Bun in an existing codebase (bun v1.0.15). This would be really great to have support for since Got is such a popular choice for making HTTP requests in modern Node.js.

Thank you guys for all the hard work so far. ❤️

@paperdave
Copy link
Member

it is very close but there are some https / compression issues with got after the pr. i've been prioritizing windows mostly and havent had time to finish that pr.

@MetaMmodern
Copy link

MetaMmodern commented Jan 14, 2024

I see a different error, but nevertheless Got doesn't work with Bun.

972 |         });
973 |         this[kUnproxyEvents] = proxy_events_1.default(request, this, proxiedRequestEvents);
974 |         this[kRequest] = request;
975 |         this.emit('uploadProgress', this.uploadProgress);
976 |         // Send body
977 |         const body = this[kBody];
                                                                         ^
RequestError: Unable to connect. Is the computer able to access the url?
 code: "ConnectionRefused"

      at projectName/node_modules/got/dist/source/core/index.js:977:68
      at projectName/node_modules/@szmarczak/http-timer/dist/source/index.js:48:34
      at native:1:1
      at promiseReactionJob (native:1:1)
      at processTicksAndRejections (native:1:1)

The code I ran is same as minimal repro in comments above.

@paperdave let us know please if there's a Bun internal library that could replace got or any other recommended lib. thanks
found it supports fetch. neat! https://bun.sh/guides/http/fetch

@RokoTechnology
Copy link

can confirm still issue as of bun 1.0.25 and got 14.0.0

@jdalton
Copy link
Contributor

jdalton commented Jan 22, 2024

@paperdave

it is very close but there are some https / compression issues with got after the pr. i've been prioritizing windows mostly and havent had time to finish that pr.

The PR at #4395 seems really involved. Would a quick fix be to simply add the setter?

Update:

Related PR fix for the setter: #8368

@luckyyyyy
Copy link

luckyyyyy commented Mar 17, 2024

This is currently one of the issues blocking me, is there any progress?
image

@edgarasben
Copy link

The same issue still in bun 1.1.0

@IAkumaI
Copy link

IAkumaI commented Apr 19, 2024

The issue is still here in the latest 1.1.4
Any updates?

@edgarasben
Copy link

Yes, got package still doesn't work in 1.1.4

@ztimar31
Copy link

I experience the same error with got using bun version 1.1.4

[0-0] 89 |                 Object.assign(this.options.headers, source.headers);
[0-0] 90 |             }
[0-0] 91 |         });
[0-0] 92 |         this.on('newListener', event => {
[0-0] 93 |             if (event === 'retry' && this.listenerCount('retry') > 0) {
[0-0] 94 |                 throw new Error('A retry listener has been attached already.');
[0-0]                            ^
[0-0] error: A retry listener has been attached already.
[0-0]       at /Users/timarzoltan/dev/dc-automation-wdio/node_modules/got/dist/source/core/index.js:94:23
[0-0]       at makeRequest (/Users/timarzoltan/dev/dc-automation-wdio/node_modules/got/dist/source/as-promise/index.js:113:13)
[0-0]       at /Users/timarzoltan/dev/dc-automation-wdio/node_modules/got/dist/source/as-promise/index.js:131:9
[0-0]       at /Users/timarzoltan/dev/dc-automation-wdio/node_modules/p-cancelable/index.js:68:4
[0-0]       at new Promise (:1:21)
[0-0]       at new PCancelable (/Users/timarzoltan/dev/dc-automation-wdio/node_modules/p-cancelable/index.js:34:19)
[0-0]       at asPromise (/Users/timarzoltan/dev/dc-automation-wdio/node_modules/got/dist/source/as-promise/index.js:21:21)
[0-0]       at lastHandler (/Users/timarzoltan/dev/dc-automation-wdio/node_modules/got/dist/source/create.js:42:27)
[0-0]       at iterateHandlers (/Users/timarzoltan/dev/dc-automation-wdio/node_modules/got/dist/source/create.js:49:19)
[0-0]       at /Users/timarzoltan/dev/dc-automation-wdio/node_modules/webdriver/build/request/node.js:17:27
[0-0]       at _libRequest (/Users/timarzoltan/dev/dc-automation-wdio/node_modules/webdriver/build/request/node.js:15:23)
[0-0]       at /Users/timarzoltan/dev/dc-automation-wdio/node_modules/webdriver/build/request/index.js:147:30
[0-0]       at _request (/Users/timarzoltan/dev/dc-automation-wdio/node_modules/webdriver/build/request/index.js:140:20)

@palmamartin
Copy link

I'm seeing the following error using bun version 1.1.4. A third-party library uses got which we depend on to use:

1212 |         this[kStopReading] = true;
1213 |         if (!(error instanceof RequestError)) {
1214 |             error = new RequestError(error.message, error, this);
1215 |         }
1216 |         const typedError = error;
1217 |         const { response } = typedError;
                    ^
RequestError: Attempted to assign to readonly property.
 code: "ERR_GOT_REQUEST_ERROR"

      at _beforeError (/Users/m/src/github.com/project/importer/node_modules/got/dist/source/core/index.js:1217:14)
      at /Users/m/src/github.com/project/importer/node_modules/got/dist/source/core/index.js:1262:35
      at asyncFunctionResume (native:1:1)
      at promiseReactionJobWithoutPromiseUnwrapAsyncContext (native:1:1)
      at promiseReactionJob (native:1:1)
      at processTicksAndRejections (native:1:1)
      at /Users/m/src/github.com/project/importer/node_modules/got/dist/source/core/index.js:1043:21
      at _onResponseBase (/Users/m/src/github.com/project/importer/node_modules/got/dist/source/core/index.js:778:27)
      at /Users/m/src/github.com/project/importer/node_modules/got/dist/source/core/index.js:948:24
      at _onResponse (/Users/m/src/github.com/project/importer/node_modules/got/dist/source/core/index.js:946:23)
      at /Users/m/src/github.com/project/importer/node_modules/got/dist/source/core/index.js:962:23
      at emit (native:1:1)
      at /Users/m/src/github.com/project/importer/node_modules/@szmarczak/http-timer/dist/source/index.js:43:20
      at node:http:916:58

@IAkumaI
Copy link

IAkumaI commented Apr 23, 2024

@palmamartin I saw this error on the not last version of got, too.
In fact, no one got version works

@SteveYuOWO
Copy link

Yes, got package still doesn't work in 1.1.5

@nxht
Copy link

nxht commented May 22, 2024

It seems the issue is fixed in 1.1.9 during #11082 ?
For my case, the got library works fine now.

@edgarasben
Copy link

edgarasben commented May 22, 2024

Yes, got is now working in 1.1.9!

@IAkumaI
Copy link

IAkumaI commented May 22, 2024

Confirm. Also works. Not production tested, but at least works on simple requests

@IAkumaI
Copy link

IAkumaI commented May 29, 2024

Hm...seems like it has some problems with https websites.
For example

await got('https://github.com/');

Hangs forever. Timeout, error catching, anything does not work at all. Tested on 1.1.10

@nektro
Copy link
Member

nektro commented Aug 15, 2024

looks like this appears to be working now :) if any other issues are discovered feel free to open a new issue, but for now we'll close this one. you may need to run bun upgrade to get the latest fixes.

@nektro nektro closed this as completed Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.