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
The getaddrinfo error can be solved by passing the entire URL instead of the options to the http. get() function. You can kick away the getaddrinfo error by adding the missing localhost line in the hosts file while using localhost.
If you try to run your JSON server and see this error message “getaddrinfo ENOTFOUND localhost,” it's happening because Webpack cannot find your localhost address. In my case one line from the Hosts file was missing on my computer and I had to figure out how to add it back in.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With