Maxqueue
Maxqueue

Reputation: 2444

React npm start 127.0.0.1 instead of localhost on windows

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

Upvotes: 1

Views: 11352

Answers (2)

Maxqueue
Maxqueue

Reputation: 2444

So finally figured this out. Created a file called .env.local (mind the beginning .) containing following:

HOST=127.0.0.1

Upvotes: 4

Yann Léon
Yann Léon

Reputation: 1

For those who this answer (Maxqueue) does not work try :

  • Renaming the file .env.local (add the dot)
  • run yarn or npm one more time

worked for me !

Upvotes: 0

Related Questions