Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng serve error: getaddrinfo ENOTFOUND localhost

Tags:

angular

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

like image 554
sanjihan Avatar asked Sep 13 '17 18:09

sanjihan


People also ask

How do I fix Getaddrinfo Enotfound error?

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.

What does error Getaddrinfo Enotfound mean?

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.


1 Answers

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

like image 175
jyotisankar Avatar answered Oct 30 '22 16:10

jyotisankar