My ng serve --open
command is serving at port 4200 but not opening the browser at port 4200. When the browser auto-loads, only 'localhost' appears in URL, and blank page displays (well, not so much blank page as "This site can’t be reached. localhost refused to connect. ERR_CONNECTION_REFUSED). The command-line output also gives an indication of this (More Details section below), saying that the localhost port is undefined or something?
NOTE that this used to work until very recently, so either I accidentally changed some config on my end, or, a very recent browser-update or other package-update is causing this?
But when I then go and manually change the port to 4200 (by editing the URL to localhost:4200
), it then finds and displays the page that ng serve is serving.
I'm seeing this same behaviour even after I create a brand new app using ng new and doing only npm start
on that.
I didn't make any recent angular upgrades on my side. Chrome, on the other hand, pushes updates every second day and thus I'm wondering if this could be caused by something on the browser-side?
More details:
Using Angular CLI: 10.2.1
In my package.json, I have for the 'start' script:
"start": "ng serve --open --watch",
I've played around with different port numbers in that start command there, and it also doesn't seem to affect the actual port that the browser is opening my localhost at. Same goes for manually running: ng serve --open --port 4200
--> it also opens browser, but not at port 4200.
On the command-line output, ng serve shows the following:
npm start
> [email protected] start /home/schalks/personal-src/my-own-repos/ps-angular-forms
> ng serve --open --watch
chunk {main} main.js, main.js.map (main) 24.1 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 141 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.15 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 935 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 2.66 MB [initial] [rendered]
Date: 2021-02-05T11:21:50.674Z - Hash: 8b8180430b015f98e7ac - Time: 9330ms
** Angular Live Development Server is listening on localhost:undefined, open your browser on http://localhost/ **
: Compiled successfully.
question from:
https://stackoverflow.com/questions/66062535/ng-serve-is-not-opening-browser-chrome-for-localhost-at-correct-port