angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

"[WDS] Disconnected!" error on new Angular 6 project

Open Jawan81 opened this issue 8 years ago • 31 comments

After upgrading my Angular 5.2 app to 6.0 the connection to the Webpack Dev Server could not be established anymore ("[WDS] Disconnected!"). I then verified that the same problem occurs on a newly created project as well.

Versions

Angular CLI: 6.0.5
Node: 8.9.1
OS: linux ia32
Angular: 6.0.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.6.5
@angular-devkit/build-angular     0.6.5
@angular-devkit/build-optimizer   0.6.5
@angular-devkit/core              0.6.5
@angular-devkit/schematics        0.6.5
@angular/cli                      6.0.5
@ngtools/webpack                  6.0.5
@schematics/angular               0.6.5
@schematics/update                0.6.5
rxjs                              6.2.0
typescript                        2.7.2
webpack                           4.8.3

Ubuntu 16.04 Vagrant VM running under Windows 10. Port 4200 is forwarded in the Vagrantfile: config.vm.network "forwarded_port", guest: 4200, host: 4200

Repro steps

  • Step 1: ng new blabla in the VM
  • Step 2: ng serve --host 0.0.0.0 --port 4200 --disable-host-check
  • Step 3: Open http://<ip-of-my-vm>:4200 in the host's browser (Firefox and Chrome tested)
  • Step 4: The page loads successfully, but [WDS] Disconnected! appears in the browser's console

Observed behavior

As similar [WDS] problems seem to have struggled a lot of people in the past I tried to follow their advices but never found something to solve it. To narrow down the error I created a new project to see if the error persists - and it does.

When I follow the above steps the [WDS] Disconnected! error occurs and live updates don't work. I have stepped through what is happening before that error and noticed that SockJS cannot establish a connection because all its 'transport' mechanism return 'disabled'. For example in SockJS's sockjs-client/lib/transport/websocket.js you find this:

...
WebsocketDriver = require('./driver/websocket'); // should include faye-websocket
...
WebSocketTransport.enabled = function() {
  return !!WebsocketDriver; // will return false
};

But WebsocketDriver is undefined although Websockets are supported by the browsers I use (FF 60, Chrome 66). The other transport mechanisms of SockJS also return false when enabled is requested on them so SockJS has no valid transport mechanism left and closes the connection before any request has been made which then causes the output of [WDS] Disconnected!.

Desired behavior

As I had no problems with the dev server in my setup when using Angular 4 or 5 I would have expected the ng serve command to still work the way it has. But something must have changed in either the webpack dev server, SockJS, faye-websocket or the angular cli that now makes this error pop up. I unfortunately couldn't find out what.

Mention any other details that might be useful (optional)

I also tried out if there's a difference when using nginx as a reverse proxy instead of using the VM's forwarded port, but there isn't...

fyi: For the Angular 5.2 project I used the same version of node

Jawan81 avatar May 29 '18 15:05 Jawan81

This is a configuration issue and will not be fixed. You can use --disable-host-check to fix it, but it will open your computer to any access from any other computer. Maybe it's okay for you, maybe not.

The proper way to fix this is to implement a reverse proxy to your development server, which requires a lot more than what ng serve was meant to do. My solution is to print a warning when using this.

hansl avatar Jan 14 '19 17:01 hansl

The Invalid Host/Origin Header problem I reported above (same like in @MichFe's screenshot) had suddenly appeared for us on 2018/12/22 (for different developers independently, after having created new projects with ng new ...). But some days later the problem disappeared just as suddenly. This was not related to the Angular CLI version. Projects which were created in those days are now working fine as well for us - without the mentioned workaround -, after deleting node_modules, package-lock.json and running npm i.

jostschmithals avatar Jan 14 '19 19:01 jostschmithals

In angular.json, add the following under architect -> serve -> options: "disableHostCheck": true

fredrik-macrobond avatar Jan 18 '19 12:01 fredrik-macrobond

issue resolved after adding below in polyfills.ts file: import 'core-js/es7/object'; import 'core-js/es7/array';

chowdam avatar Jan 22 '19 19:01 chowdam

I have set "disableHostCheck": true.

Still getting this error, constantly. If I change tabs in Chrome and let the tab load in the background, it works fine.

I can also temporarily resolve it by killing the dev server and restarting npm start.

cfremgen avatar Mar 05 '19 14:03 cfremgen

received this error too "[WDS] Disconnected!" on firefox. It's ok when the page is loaded for the first time but, if I reload or refresh the page this error appears. Anyway to fix this ? Already tried the fixes above nothing works.

Angular CLI: 7.3.5 Node: 8.10.0 OS: linux x64 Angular: ...

Package Version

@angular-devkit/architect 0.13.5 @angular-devkit/core 7.3.5 @angular-devkit/schematics 7.3.5 @schematics/angular 7.3.5 @schematics/update 0.13.5 rxjs 6.3.3 typescript 3.2.4

0x3ch0 avatar Mar 14 '19 06:03 0x3ch0

any update on this one, it seems to only appear on initial load and if i reload the page the error disappears.

chan-dev avatar Apr 02 '19 09:04 chan-dev

I had the same issue after upgrading to Angular 6.0. I found that my inastalled zone.js version was 9.0. I downgraded to ^0.8.26 and it worked.

himanshujoshi15 avatar Apr 04 '19 13:04 himanshujoshi15

I had the same issue after upgrading to Angular 6.0. I found that my inastalled zone.js version was 9.0. I downgraded to ^0.8.26 and it worked.

I tried this downgrade fix but didn't worked for me using Angular 7.3.7.

Opened a new thread for this because the TS here Closed this thread.

https://github.com/angular/angular-cli/issues/13915

Follow the link above for the others who's facing this problem too. It's still open as of now.

0x3ch0 avatar Apr 08 '19 04:04 0x3ch0

el mismo error, al iniciar no aparece.. despues de refrescar la pagina si

[WDS] Disconnected! client:177 close (index):177 onclose socket.js:17 dispatchEvent sockjs.js:170 _close sockjs.js:969 invokeTask zone.js:423 runTask zone.js:195 invokeTask zone.js:498 invoke zone.js:487 timer zone.js:2281

cazadorv avatar Apr 29 '19 23:04 cazadorv

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.