webpack-dev-server: Weird error about global.WebSocket

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

/**
 * WebSocket constructor.
 */

var WebSocket = global.WebSocket || global.MozWebSocket;

global is undefined so, it throw error. But when I test using ws with browserify, it was window.

I am trying to use react-hot-loader and can’t figure this out.

My config for entry is:

[ 
  `webpack-dev-server/client?${webpackDevServerUrl}`,
  'webpack/hot/only-dev-server',
  'src/js/index'
]

Hope someone who experienced this could help. Thanks a lot.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

I think the more correct way to get window is Function('return this')() instead. The content in Function constructor is non-strict regardless of the environment it is created in.

Babel is driving me nuts! You can’t just put "use strict" before every code…