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

browserify support #455

Closed
tilgovi opened this issue Mar 2, 2013 · 22 comments · Fixed by #944
Closed

browserify support #455

tilgovi opened this issue Mar 2, 2013 · 22 comments · Fixed by #944

Comments

@tilgovi
Copy link

tilgovi commented Mar 2, 2013

While working on tilgovi/chromify last month I ran into an issue where the mime types file couldn't be read by request (because it wasn't included). At the time I hacked around it hard by bundling the mime types file through emscripten and a readFileSync that read from that.

With the 'browser' attribute of either request or the mime types module I bet we can preload the data so that it just works.

I'll look into it and come back with a PR over the weekend.

@mikeal
Copy link
Member

mikeal commented Mar 2, 2013

we need to get a pull request in to the mime module.

@joaojeronimo
Copy link
Contributor

Getting there: https://github.com/dominictarr/node-mime

@max-mapper
Copy link

bumping this with an update: https://twitter.com/maxogden/status/413057941185372160

tl;dr @mikeal said he's hoping to work on this over xmas break

@kyledrake
Copy link

Did santa deliver on this one? Want to use it for NeoCities API client for node http://neocities.org/api

@max-mapper
Copy link

http://npmjs.org/xhr is the best bet right now, it got some love recently.

@ghost
Copy link

ghost commented May 21, 2014

broofa/mime#61

@ghost
Copy link

ghost commented May 31, 2014

Some folks forked node-mime and took on browser-compatibility. It should be a trivial drop-in replacement: https://github.com/expressjs/mime-types

@mikeal
Copy link
Member

mikeal commented May 31, 2014

I'll +1 a PR that swaps the mime library fro one that is browserifyable.

@eiriksm
Copy link
Member

eiriksm commented Jun 25, 2014

Hello.

So the issue referenced right above this comment should fix that mime problem and get request ready for being "browserified" without error. However, I ran into one additional issue while using request with browserify. I am pretty sure you guys have a better understanding as to how to proceed with it, but this is the temporary hack I added:

diff --git a/request.js b/request.js
index caa1394..001a380 100644
--- a/request.js
+++ b/request.js
@@ -716,7 +716,7 @@ Request.prototype.onResponse = function (response) {
     debug('response end', self.uri.href, response.statusCode, response.headers)
   });

-  if (response.connection.listeners('error').indexOf(self._parserErrorHandler) === -1) {
+  if (response.connection && response.connection.listeners('error').indexOf(self._parserErrorHandler) === -1) {
     response.connection.once('error', self._parserErrorHandler)
   }
   if (self._aborted) {
@@ -725,7 +725,7 @@ Request.prototype.onResponse = function (response) {
     return
   }
   if (self._paused) response.pause()
-  else response.resume()
+  else response.resume && response.resume()

As you might understand, response.resume and response.connection is undefined in the browser, and I have a feeling this might come from browserify-http or something like that. It's a lot of code to read through, so if this is really obvious to anyone, please chime in

(also if my temporary hack is the only way to go, and you feel like it's alright, I'll open another PR for it)

@mikeal
Copy link
Member

mikeal commented Jun 25, 2014

why doesn't response have a resume() method? i would think that the stream shim would provide that?

@mikeal
Copy link
Member

mikeal commented Jun 25, 2014

oh, also, can you put a comment on each of these lines saying that it is for browserify, cause i'm going to forget this entirely in the next refactor :)

@eiriksm
Copy link
Member

eiriksm commented Jun 25, 2014

Sorry if my question was not so obvious, but does that mean you want me to create a PR with those lines? (including comments of course)

My comment was also meant as a question (as you mention yourself) as to why this does not work. :)

But PR it is, if you want... :)

@mikeal
Copy link
Member

mikeal commented Jun 25, 2014

I'm interested in why this is required but that doesn't mean I won't accept a workaround right now that gets us to a browserifyable request :)

@eiriksm
Copy link
Member

eiriksm commented Jun 25, 2014

I like (and agree with) the pragmatism :)

Pull request sent.

@mikemaccana
Copy link

FYI current request 2.48.0 on npm still uses a form-data 0.1.4, which uses mime 1.2.11 that does content = fs.readFileSync(file, 'ascii') and fails on mime.js:55 when called from browserify.

@eiriksm
Copy link
Member

eiriksm commented Dec 4, 2014

This was apparently introduced in 2.46 or something, when form-data started to be a dependency instead of an optional dependency. PR to form-data, maybe?

@nylen
Copy link
Member

nylen commented Dec 4, 2014

Ping @mikeal re bounty on this issue

See form-data/form-data#87, looks like it just needs some cleanup.

@eiriksm
Copy link
Member

eiriksm commented Dec 5, 2014

Just tested replacing the mime library in form-data, and that fixes the issue. Sent a cleaned up PR just like the above mentioned.

@nylen nylen closed this as completed in e165ee3 Dec 7, 2014
nylen added a commit that referenced this issue Dec 7, 2014
Upgrade form-data, add back browserify compability. Fixes #455.
@eiriksm
Copy link
Member

eiriksm commented Dec 8, 2014

Can we publish a new version, by the way?

@tschaub
Copy link
Contributor

tschaub commented Dec 9, 2014

Also, can someone list the last known version to work with browserify? Until a new version is published, it would be good for folks who find this to be able to know what works.

@tschaub
Copy link
Contributor

tschaub commented Dec 9, 2014

It looks like 2.40.0 works with browserfiy. Though this doesn't provide HTTPS support. 2.46.0 should have HTTPS support in the browser (with #1173) but this has a transitive dependency on a non-browser friendly version of the mime module.

@nylen
Copy link
Member

nylen commented Dec 9, 2014

2.50.0 is out now. Let us know if you have any problems with it.

zordius pushed a commit to zordius/fluxex that referenced this issue Dec 10, 2014
paulmand3l added a commit to paulmand3l/sparkjs that referenced this issue Feb 14, 2015
request/request#455 (comment)

Also, the browser-request library doesn't include the .on function used here https://github.com/spark/sparkjs/blob/master/lib/spark.js#L667, so trying to do any event subscribing in the browser just results in 'undefined is not a function' in a minified file, which isn't super helpful.
phillbaker added a commit to phillbaker/digitalocean-node that referenced this issue Mar 18, 2016
…ary.

Note this depends on request's built in support for being browser friendly: request/request#455.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants