Skip to content

require('webwocket').client fails if _global returns undefined (browser.js:1) #287

@jhudson8

Description

@jhudson8

I'm using webpack v2 to bundle my app and I'm not sure why but the this in the following code block

var _global = (function() { return this; })();

returns undefined which causes the following error

Uncaught TypeError: Cannot read property 'WebSocket' of undefined

https://github.com/theturtle32/WebSocket-Node/blob/master/lib/browser.js#L1

To resolve this, I added the following code

var _global = (function() {
  if (!this && typeof global !== 'undefined') {
    return global;
  }
  return this;
})();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions