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

Doesn't work in a browser environment (with browserify) for later versions #1252

Closed
limikael opened this issue Nov 8, 2014 · 36 comments
Closed

Comments

@limikael
Copy link

limikael commented Nov 8, 2014

Hi,

I'm using request together with browserify, which used to work fine. However, it doesn't do that anymore... I know that is works for 2.40.0, and for 2.47.0 it does not. Not sure exactly in which version the problem appeared.

However, the problem I'm getting is that is that is chokes on a line that looks like this:

  content = fs.readFileSync(file, 'ascii'),

Sorry for the not very detailed report. Do you need more info I'm happy to provide that.

@simov
Copy link
Member

simov commented Nov 8, 2014

Can you tell us where exactly this content variable is used in your request configuration?

@limikael
Copy link
Author

limikael commented Nov 8, 2014

It is not used at all in my configuration. Sorry for the confusion...

This error happens as soon as I do:

var request=require("request");

If the version of request is 2.47.0. If the version is 2.40.0 it works fine.

@limikael
Copy link
Author

limikael commented Nov 8, 2014

Hi again,

Here is a bit more info... I created a file that just looks like:

var request = require("request");

console.log("hello");

And compiled it with browserify for the versions 2.40.0 and 2.47.0 of request. The versions are deployed here, with a really simple .html page that loads them:

http://limikael.altervista.org/requesttest/requesttest.2.47.0.html
http://limikael.altervista.org/requesttest/requesttest.2.40.0.html

When I visit them with a browser (Chrome Version 38.0.2125.104) and look at the javascript console I get different results. For the 2.40.0 I see "hello" there, as one would expect. For the 2.47.0 version I see this error:

Uncaught TypeError: undefined is not a function requesttest.bundle.2.47.0.js:4863
Mime.load requesttest.bundle.2.47.0.js:4863
__browserify_process requesttest.bundle.2.47.0.js:4899
s requesttest.bundle.2.47.0.js:1
(anonymous function) requesttest.bundle.2.47.0.js:1
...

If I look at the offending line in the bundle at line 4863, it is the same one:

content = fs.readFileSync(file, 'ascii'),
lines = content.split(/[\r\n]+/);

The context around this function looks like this. Don't know which source file it comes from exactly since it is bundled with browserify:

/**
 * Load an Apache2-style ".types" file
 *
 * This may be called multiple times (it's expected).  Where files declare
 * overlapping types/extensions, the last file wins.
 *
 * @param file (String) path of file to load.
 */
Mime.prototype.load = function(file) {

  this._loading = file;
  // Read file and split into lines
  var map = {},
      content = fs.readFileSync(file, 'ascii'),
      lines = content.split(/[\r\n]+/);

  lines.forEach(function(line) {
    // Clean up whitespace/comments, and split into fields
    var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
    map[fields.shift()] = fields;
  });

  this.define(map);

  this._loading = null;
};

Hope this helps! Let me know if you need more info!

@simov
Copy link
Member

simov commented Nov 8, 2014

The form-data module that we're using internally is depending on the mime module, which in turn contains the offending line. No idea what changed there, probably it's good idea to ask there too.

@nylen
Copy link
Member

nylen commented Nov 8, 2014

@mikeal and collaborators, what do you think about placing a bounty on getting request working in the browser?

@limikael
Copy link
Author

limikael commented Nov 8, 2014

I'll pitch in 0.1 BTC towards the bounty

@charliedowler
Copy link

+1

This should fix it right?

form-data/form-data#87

@nylen
Copy link
Member

nylen commented Nov 9, 2014

Yes, with some tweaking, but I wouldn't be surprised if there were other issues once that's resolved.

@limikael
Copy link
Author

limikael commented Nov 9, 2014

Hi,

I'm not following 100% what the relationship is between the various projects, request, node-form-data and mime-types.

Anyway... 0.1 BTC was promised and I tried to create a bounty here and pay with bitcoin:

https://www.bountysource.com/issues/5856132-doesn-t-work-in-a-browser-environment-with-browserify-for-later-versions

However, don't know what happened, my bitcoin seems to be lost in cyberspace somehow...

Anyway, if this gets resolved and someone posts a bitcoin address I will happily put 0.1 BTC there... :)

@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.

@limikael
Copy link
Author

limikael commented Dec 4, 2014

Ok will test it... Something sträng happened at bountysource, but will
happily pay out to a bitcoin address once everything is working out of the
box and is published to the public npm repo...
Den 4 dec 2014 19:56 skrev "James Nylen" notifications@github.com:

Ping @mikeal https://github.com/mikeal re bounty on this issue

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


Reply to this email directly or view it on GitHub
#1252 (comment).

@nylen
Copy link
Member

nylen commented Dec 4, 2014

@limikael the reason I bring up a bounty is we have a pretty decent balance on bountysource just sitting there, but I can't assign any of it (and I wouldn't anyway without agreement from other maintainers).

@limikael
Copy link
Author

limikael commented Dec 5, 2014

Hi, I'm sorry but I don't understand exactly how form-data/form-data#87 is related to this problem and how I can test if it solves it. I'm encountering the problem because of different versions of the request module, but you are referencing something else. I assume that you are doing that because one depends on the other in a way that is very obvious to you, but it's not obvious to me.

So if that takes care of if, what do we also need to change in the request module so this module uses the right version?

@nylen
Copy link
Member

nylen commented Dec 6, 2014

As of more recent versions, request depends on form-data which depends on the broken mime library. If form-data will switch to mime-types instead and release a new version, then we can move to the new version of form-data.

I suppose you could test it by making this change in your local copy of form-data (probably installed at node_modules/request/node_modules/form-data or similar).

@nylen
Copy link
Member

nylen commented Dec 6, 2014

Now there's form-data/form-data#95 which looks to me like it's ready to go. And, over at #455 @eiriksm has tested this and confirmed that it works.

@alexindigo
Copy link
Contributor

Published 0.2.0 https://www.npmjs.org/package/form-data

@nylen
Copy link
Member

nylen commented Dec 6, 2014

Great, thanks @alexindigo! Now we just need a PR with the new version of form-data.

@eiriksm
Copy link
Member

eiriksm commented Dec 7, 2014

PR sent over at #1307

@nylen
Copy link
Member

nylen commented Dec 7, 2014

Fixed at #1307.

@nylen nylen closed this as completed Dec 7, 2014
@limikael
Copy link
Author

limikael commented Dec 8, 2014

Great! Ok there is then 0.1 BTC sitting here in my wallet that I promised for anyone who resolved this... Bountysource was a little strange, but if someone has a bitcoin address I will just send it... Or maybe I will try this changetip thingy, don't know if it integrates with github but it should...

@nylen
Copy link
Member

nylen commented Dec 8, 2014

Don't know if @eiriksm does bitcoin but I nominate him.

@eiriksm
Copy link
Member

eiriksm commented Dec 8, 2014

Hey. Thanks for that thought.

Well, we all pitched in here I would say. I nominate that it is the season of giving, so if possible, how about donating it to a good cause?

@limikael
Copy link
Author

limikael commented Dec 8, 2014

@eiriksm Wow that's very noble! I have signed up for changetip and I'm learning how it works now... When that is done I will spread som tip around me here in the thread and then you can spread it on if you want... changetip seems like a cool thing... :)

@limikael
Copy link
Author

limikael commented Dec 8, 2014

Ok @eiriksm trying this now... Have yourself 1 dinner or pass it on! 👍 @changetip

@changetip
Copy link

Hi @eiriksm, @limikael sent you a Bitcoin tip worth 1 dinner (40,673 bits/$15.00), and I'm here to deliver it ➔ collect your tip.

Learn more about ChangeTip

@limikael
Copy link
Author

limikael commented Dec 8, 2014

And @nylen, you certanly deserve 1 applause for your great work! @changetip

@changetip
Copy link

Hi @nylen, @limikael sent you a Bitcoin tip worth 1 applause (27,115 bits/$10.00), and I'm here to deliver it ➔ collect your tip.

Learn more about ChangeTip

@limikael
Copy link
Author

limikael commented Dec 8, 2014

@alexindigo, thanks! Have 1 pizza! @changetip

@changetip
Copy link

Hi @alexindigo, @limikael sent you a Bitcoin tip worth 1 pizza (27,121 bits/$10.00), and I'm here to deliver it ➔ collect your tip.

Learn more about ChangeTip

@limikael
Copy link
Author

limikael commented Dec 8, 2014

@charliedowler, 1 high-five @changetip

@changetip
Copy link

Hi @charliedowler, @limikael sent you a Bitcoin tip worth 1 high-five (13,560 bits/$5.00), and I'm here to deliver it ➔ collect your tip.

Learn more about ChangeTip

@limikael
Copy link
Author

limikael commented Dec 8, 2014

@simov 1 brat! @changetip

@alexindigo
Copy link
Contributor

@limikael thanks for the tip, although I just clicked Merge button, all the work done by @eiriksm so he deserves all the pizza :)

@eiriksm
Copy link
Member

eiriksm commented Dec 8, 2014

Woah. Thanks for that. I'm keeping my word and donating it to a local charity.

And thanks for those kind words @alexindigo .

@charliedowler
Copy link

+1 cheers guys

@limikael
Copy link
Author

limikael commented Dec 8, 2014

@eiriksm Cool! If you would like to go global then may I suggest Tunapanda, it was when developing software for them that this problem appeared... :)

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

No branches or pull requests

7 participants