React npm start 127.0.0.1 instead of localhost on windows

Issue

So i am trying to launch my react application using 127.0.0.1 instead of localhost.

Here is what i tried:

  1. in scripts i put the following for start

    "start": "set HOST=127.0.0.1 && react-scripts start"
    

    This yields following error:

    Attempting to bind to HOST environment variable: 127.0.0.1
    If this was unintentional, check that you haven't mistakenly set it in your shell.
    Learn more here: 
    node:events:346
       throw er; // Unhandled 'error' event
       ^
    Error: getaddrinfo ENOTFOUND 127.0.0.1
     at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:26)
    Emitted 'error' event on Server instance at:
     at GetAddrInfoReqWrap.doListen [as callback] (node:net:1493:12)
     at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:69:17) {
    errno: -3008,
    code: 'ENOTFOUND',
    syscall: 'getaddrinfo',
    hostname: '127.0.0.1 '
    

I also tried updating my hosts file to have following line:
localhost 127.0.0.1

Note that i can launch 127.0.0.1 in launch.json but that only applies to when i am debugging

Solution

So finally figured this out. Created a file called env.local containing following:

HOST=127.0.0.1

Answered By – Maxqueue

Answer Checked By – Katrina (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.