0

I import the socket.io module by:

import io from 'socket.io'

and then use webpack to pack it. I try to use the packed js file in html, but I found that the global is undefined at the place:

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

I am a newbie on it. Anyone can help me?

fcbflying
  • 693
  • 1
  • 7
  • 23
  • For client, you are supposed to use socket.io-client library. Check the docs https://github.com/socketio/socket.io – cdoshi Dec 27 '17 at 09:13
  • @cdoshi okay, that just an example, I also tried other js modules uses global, but after webpack the global is undefined, I don't know why. Someone told me need to config sth. like node.global=true, but it does not work for me: https://stackoverflow.com/questions/34856005/global-undefined-after-running-webpack – fcbflying Dec 27 '17 at 09:25
  • Are you getting an error? Why are you using global variable and where have you defined it? Sorry but there are not enough details to answer your question – cdoshi Dec 27 '17 at 09:42
  • @cdoshi I have a dependency js module, it uses the global ,for example socket-io-client. If I use 'require' way, it works fine and I saw the global is a Window object through Chrome debug tool, but if I use the import way directly like 'import io from 'socket-io-client', and then use webpack to pack it, the global will be undefined through Chrome debug tool. – fcbflying Dec 27 '17 at 09:55
  • Can you try import * as io from 'socket.io' – cdoshi Dec 27 '17 at 10:23
  • @cdoshi It still doesn't work. – fcbflying Dec 27 '17 at 11:06

0 Answers0