Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack-dev-server can't find localhost

I'm trying to get started with React using webpack, but keep running into an error when I try to set up webpack-dev-server. I ran

npm install webpack-dev-server

followed by

webpack-dev-server

and the command line returns the following:

events.js:154
      throw er; // Unhandled 'error' event
      ^

Error: getaddrinfo ENOTFOUND localhost
    at errnoException (dns.js:26:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)

Any clues on what is happening here?

I don't really know how webpack works to try and search for the root of the problem, but I've also been developing a website using PHP at port 80 with MAMP, I don't know if this is maybe part of the issue?

like image 731
lizzie-cd Avatar asked Mar 02 '16 20:03

lizzie-cd


2 Answers

Solved, turned out my hosts file (found under /etc/hosts on a mac) had one line missing and so webpack couldn't find localhost. I restored it to its default following these instructions and it now works!

like image 151
lizzie-cd Avatar answered Sep 18 '22 20:09

lizzie-cd


In latest mac and linux os , the webpack dev server wokinnly only on adding the

host: "127.0.0.1"

inside the devServer in the webpack.config

like image 45
Bharathan Kumaran Avatar answered Sep 17 '22 20:09

Bharathan Kumaran