webpack-dev-server can't find localhost

99封情书 提交于 2019-12-05 02:37:27

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!

The most common reason for that error is that you have something else already using that port. Try starting it on another port.

webpack-dev-server --port 3001

Make sure your /etc/hosts file includes localhost.

Open /etc/hosts

$ sudo vi /etc/hosts

Copy and paste this, if it's missing:

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost

Did not work for me even after restoring the hosts file and trying with a different port. The way I made it to work was to give a custom host (127.0.0.1) and port (3001 or any other available) when starting the server:

webpack-dev-server --host 127.0.0.1 --port 3001

Also check if /etc/hosts have 127.0.0.1 pointing to localhost as well.

JaNe

Also encountered the same error and nothing fixed it.

It appears, in my case, that I accidentally "corrupted" the /etc/hosts file by been able to write to it without the sudo permission.

The clue was when I cat /etc/hosts the output was one messy line. I deleted and re-created the file as sudo, with the @lizzie-cd link and all went back to normal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!