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

Uncaught TypeError: response.setEncoding is not a function #961

Closed
jstoeffler opened this issue Apr 17, 2016 · 5 comments
Closed

Uncaught TypeError: response.setEncoding is not a function #961

jstoeffler opened this issue Apr 17, 2016 · 5 comments

Comments

@jstoeffler
Copy link

Hi,

I tried to install socket.io-client in a meteor app, it seems that browserify is responsible (see this issue), but I'm posting this here, because I believe other could have the same issue (and in case someone knows a better fix). Feel free to close the issue if you find it appropriate.

So my app crashes there, it's in the node-XMLHttpRequest (the repository doesn't accept issues), which is required by engine.io, which itself is required by socket.io-client.

So I decided to hack the browserify response object, like this:

import Response from 'meteor-node-stubs/node_modules/http-browserify/lib/response';
if(!Response.prototype.setEncoding) {
    Response.prototype.setEncoding = function(encoding){
        // do nothing
    }
}

And so far it works.

@shaharyar123
Copy link

where to put this code ? any specific file ?

@jstoeffler
Copy link
Author

jstoeffler commented Sep 21, 2016

In any file that gets loaded before you use the library.

Some main/index file would work. If you have an entry point for the code related to socket-io it's better. Or you could put it in a separate file that you'd name specifically so other understand it's a dirty fix, and then import it in a main/index file.

@shaharyar123
Copy link

i have put this code in run(), it returns setEncoding = undefined, then i assign a function to it (according to your solution) ,it returns setEncoding = function, afterwords it returns setEncoding = undefined and gives error. i think the XMLHttpRequest.js load continuously that's why its re-change the type of setEncoding ?

@jstoeffler
Copy link
Author

jstoeffler commented Sep 23, 2016

That's weird. What's the run() function you're talking about ?

You probably want to do this outside a function, before your code is executed.

I don't understand why the Response prototype would change though.

@darrachequesne
Copy link
Member

Closed due to inactivity, please reopen if needed.

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

3 participants