Reputation: 6004
I was getting this error:
getaddrinfo ENOTFOUND localhost
Error: getaddrinfo ENOTFOUND localhost
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
when running ng serve
. After web lookup, the proposed answer to this problem is to run this command instead:
ng serve --port 4200 --host 0.0.0.0
Unfortunately, the instructions came without explanation.
This works and the Angular project compiled successfully. I am not sure why. Can someone explain why this works and what has happened in the background? Thanks
Upvotes: 12
Views: 20454
Reputation: 366
For the person who use windows.
I have the same problem in angular.
C:\Windows\System32\drivers\etc\hosts.txt
.localhost
to 127.0.0.1
line # localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
Upvotes: 0
Reputation: 162
In my case, it was a corrupted 'hosts' file. A nightly update on my MAC OS caused it. This error made no sense at first and all conditions were misleading:
Upvotes: 0
Reputation: 1274
For those of you who work with docker, I had this issue because my docker was stuck, reset the docker application and everything was working again.
Upvotes: 0
Reputation: 5524
--host
option does not work until there is an explicit entry in hosts
file for your Operating system. I solved it adding a host entry inside hosts' file under
~/etc/hosts` on ubuntu OS.
hosts
filesudo vim /etc/hosts // you could use nano or something else as per your preferred editor
Upvotes: 8
Reputation: 20014
The issue for me was the host entry:
Since I was on MAC
I cmd+space bar
type terminal
then
sudo nano /private/etc/hosts
add the localhost entry
^ + O to save
and
^ + x
to exit
and then my problem was resolved
Upvotes: 4
Reputation: 144
Hi I was having the same issue, my configuration is virtual host was not for localhost. At the same time this issue comes when there is conflict between your global Angular CLI version with local Angular CLI version. I tried with ng serve --port 4200 --host 127.0.0.1 that works for me.
Thanks
Upvotes: 8