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

superagent.get(...).buffer is not a function #1517

Comments

@iaq3
Copy link

iaq3 commented Oct 9, 2019

installed through npm

Having trouble using simple buffer function.

const superagent = require('superagent');

superagent.get(url).buffer(true).parse(superagent.parse.image)
      .then((res) => res) 

results in
superagent.get(...).buffer is not a function

Any help would be greatly appreciated, from all the guides and sample code I've read through, this should work fine.

@levino
Copy link

levino commented Dec 2, 2019

For me it works in node but I get the same error in the browser

@k-funk
Copy link

k-funk commented Dec 14, 2019

Getting the same error When upgrading from 4.1.0 -> 5.x:

request.get('/file.json').buffer(true).parse(r => r);

@niftylettuce
Copy link
Collaborator

PR welcome if you can find the fix!

@levino
Copy link

levino commented Jan 7, 2020

I wrote a try catch statement:
Try to use the node syntax, if that fails, try to use the browser syntax. Worked even though it is a bit ugly. I think the api of the library should not change between node and browser...

@niftylettuce
Copy link
Collaborator

OK I see the issue.

In the older version, client version had this:

https://github.com/visionmedia/superagent/blob/v4.1.0/lib/client.js#L631-L635

In newer version, we have this:

Request.prototype.buffer = Request.prototype.ca;
Request.prototype.ca = Request.prototype.agent;

The order in the newer version when I did the rewrite got reversed. I'm fixing it now and publishing a new version.

@niftylettuce
Copy link
Collaborator

niftylettuce commented Jan 7, 2020

@iaq3 @levino @k-funk @dews please try the latest version of superagent I just published to npm, v5.2.1

npm install superagent@latest

or with yarn:

yarn add superagent@latest

@levino
Copy link

levino commented Jan 7, 2020

Very good. Unfortunately I meanwhile have a different code that is only run on the server so we do not need the fix any more...

@k-funk
Copy link

k-funk commented Jan 7, 2020

@niftylettuce 5.2.1 fixed the bug for me. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment