Fixing create-react-app when npm fails to start because your host environment variable is being set incorrectly

My Mac’s host environment variable was set to x86_64-apple-darwin13.4.0. Seems like others have problems with it being set like this too.

$ env | grep HOST
HOST=x86_64-apple-darwin13.4.0

This causes npm startto fail in my Create React App folder.

Attempting to bind to HOST environment variable: x86_64-apple-darwin13.4.0
Error: getaddrinfo ENOTFOUND x86_64-apple-darwin13.4.0
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
Emitted 'error' event at:
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1498:12)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! zaxapp@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the zaxapp@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

This makes sense to me. My mac’s chip architecture and os (Darwin) aren’t network hosts. Maybe something else needs this variable set this way? I don’t know. To be safe, I set up a local environment variable.

To fix the problem,

  1. I wrote HOST="localhost" to ~.bash_profile via my command line editor of choice nano
  2. I “reloaded” the environment variables with source ~/.bash_profile

And now, npm is happy for create-react-app.

Maybe this will save someone else some time, or maybe someone will suggest a better way to deal with this or explain to me why my HOST was set as such. Or, maybe, this will just be another useful note to self.