Skip to content

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

Closed

Description

@jstoeffler

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.

Activity

  1. shaharyar123 commented on Sep 21, 2016

    @shaharyar123

    where to put this code ? any specific file ?

  2. jstoeffler commented on Sep 21, 2016

    @jstoeffler
    Author

    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.

  3. shaharyar123 commented on Sep 22, 2016

    @shaharyar123

    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 ?

  4. jstoeffler commented on Sep 23, 2016

    @jstoeffler
    Author

    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.

  5. darrachequesne commented on Jan 27, 2021

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions