webpack-dev-server: TypeError: Cannot read property 'headers' of null at Server.socket.on (***/node_modules/webpack-dev-server/lib/servers/SockJSServer.js:68:32)

  • Operating System: Windows 10
  • Node Version: 12.8.1
  • NPM Version: 6.10.3
  • webpack Version: 4.39.2
  • webpack-dev-server Version: since 3.5.0
  • Browser: Chrome 76
  • This is a bug
  • This is a modification request

Expected Behavior

connection should not be null

Actual Behavior

TypeError: Cannot read property 'headers' of null at Server.socket.on (***/node_modules/webpack-dev-server/lib/servers/SockJSServer.js:68:32)

For Bugs; How can we reproduce the behavior?

This bug is difficult to reproduce. It happens occasionally.

https://github.com/webpack/webpack-dev-server/blob/2d44ef8088db2312516274cc2d5edda348064712/lib/servers/SockJSServer.js#L65-L69

line 67 should become

if (connection) {
  f(connection, connection.headers)
}

For Features; What is the motivation and/or use-case for the feature?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 27 (5 by maintainers)

Most upvoted comments

什么时候可以发布新的版本啊,,我要被这个问题搞死了,或者有没有什么其他的解决方法啊,一直在等新的版本出来

@Loonride i am thinking we should mark this as bug 😞

什么时候可以发布新的版本啊,,我要被这个问题搞死了,或者有没有什么其他的解决方法啊,一直在等新的版本出来

This has been fixed in their master branch, but not yet released. I too would like a release soon, as it definitely impacts our automation, but in the meantime you can get the fix by pointing your package manager to their master branch. In NPM, that would mean changing the package.json reference to: “webpack-dev-server”: “webpack/webpack-dev-server”.

Hopefully this helps =)

ok,我对这个不太懂,我现在是降低到3.7.0的版本了,暂时没有问题,而且具体没有研究过vue-cli3初始化的项目为什么package.json中的webpack是一个,,而不是分开的

The fix is released! Seems to be working for me so far, give it few days though…

npm update/yarn upgrade (hardcore: rm -r node_modules, rm -r package-lock.json/rm -r yarn.lock and npm i/yarn install)

Please read how to use package manager

@cereallarceny try adding the following in your webpack.config.js: devServer: { contentBase: path.join(__dirname, 'dist'), compress: true, port: 3000 },

I was having the same issue and this seemed to resolve it.

stumbled upon this issue as this actually occurs randomly for me when using ng serve

Angular CLI: 8.3.3
Node: 10.16.2
OS: win32 x64
Angular: 8.2.5

I see this issue intermittently when running an Angular app from a VS Code terminal. If I close VS Code and run it from a normal cli, I don’t seem to ever see it…

We’ve been running into this issue as well. It’s generally very intermittent, but I was able to reproduce it consistently by maxing out the cpu/memory utilization of the machine our app is running on (using a prime95 torture test), then navigating to the app. It only appears to occur when navigating directly to a url, or when refreshing the page.

Checking the console output in chrome shows the following errors:

Invalid Host/Origin header
error @ index.js:169
(anonymous) @ socket.js:47
sock.onmessage @ SockJSClient.js:63
EventTarget.dispatchEvent @ eventtarget.js:51
(anonymous) @ main.js:278
SockJS._transportMessage @ main.js:276
EventEmitter.emit @ emitter.js:50
(anonymous) @ sender-receiver.js:23
EventEmitter.emit @ emitter.js:50
(anonymous) @ polling.js:30
EventEmitter.emit @ emitter.js:50
EventSourceReceiver.es.onmessage @ eventsource.js:21
index.js:172

[WDS] Disconnected!
close @ index.js:172
(anonymous) @ socket.js:26
EventTarget.dispatchEvent @ eventtarget.js:51
(anonymous) @ main.js:360
nrWrapper @ newrelic.js:369
setTimeout (async)
nrWrapper @ newrelic.js:369
SockJS._close @ main.js:348
SockJS._transportMessage @ main.js:288
EventEmitter.emit @ emitter.js:50
(anonymous) @ sender-receiver.js:23
EventEmitter.emit @ emitter.js:50
(anonymous) @ polling.js:30
EventEmitter.emit @ emitter.js:50
EventSourceReceiver.es.onmessage @ eventsource.js:21
index.js:172

[WDS] Disconnected!
close @ index.js:172
(anonymous) @ socket.js:26
EventTarget.dispatchEvent @ eventtarget.js:51
(anonymous) @ main.js:360
nrWrapper @ newrelic.js:369
setTimeout (async)
nrWrapper @ newrelic.js:369
SockJS._close @ main.js:348
SockJS._transportClose @ main.js:307
g @ emitter.js:30
EventEmitter.emit @ emitter.js:50
WebSocketTransport.ws.onclose @ websocket.js:49
websocket.js:6

WebSocket connection to 'ws://localhost:7777/sockjs-node/513/fc3v2vie/websocket' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
WebSocketBrowserDriver @ websocket.js:6
WebSocketTransport @ websocket.js:32
SockJS._connect @ main.js:219
SockJS._receiveInfo @ main.js:193
g @ emitter.js:30
EventEmitter.emit @ emitter.js:50
(anonymous) @ info-receiver.js:67
g @ emitter.js:30
EventEmitter.emit @ emitter.js:50
(anonymous) @ info-ajax.js:37
g @ emitter.js:30
EventEmitter.emit @ emitter.js:50
xhr.onreadystatechange @ abstract-xhr.js:124
nrWrapper @ newrelic.js:369

It’s also worth mentioning that adding either of the following two bits to our webpack.config.js file resolves the issue if you do what I said above; however, we’re still seeing the failure occur in our linux docker containers in CircleCI. Those settings are:

devServer: {
    hot: false,
    inline: false,
    liveReload: false
  },

  optimization: {
    splitChunks: {
      chunks: 'all'
    }
  }

“webpack-dev-server”: “webpack/webpack-dev-server”

I don’t know what you mean by this. There’s no such thing as an npm package at webpack/webpack-dev-server

Does anyone have any further information on the release schedule to resolve this?

什么时候可以发布新的版本啊,,我要被这个问题搞死了,或者有没有什么其他的解决方法啊,一直在等新的版本出来

This has been fixed in their master branch, but not yet released. I too would like a release soon, as it definitely impacts our automation, but in the meantime you can get the fix by pointing your package manager to their master branch. In NPM, that would mean changing the package.json reference to: “webpack-dev-server”: “webpack/webpack-dev-server#master”.

Hopefully this helps =)