webpack-dev-server can't find localhost

后端 未结 7 1006
刺人心
刺人心 2020-12-19 01:39

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

相关标签:
7条回答
  • 2020-12-19 01:52

    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

    0 讨论(0)
  • 2020-12-19 01:53

    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
    
    0 讨论(0)
  • 2020-12-19 02:00

    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
    
    0 讨论(0)
  • 2020-12-19 02:14

    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!

    0 讨论(0)
  • 2020-12-19 02:17

    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
    
    0 讨论(0)
  • 2020-12-19 02:17

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

    0 讨论(0)
提交回复
热议问题