Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOST is not recognized as an internal or external command [duplicate]

After cloning a Git repo with a ReactJS and NodeJS project and install NodeJS

NodeJS installed

wanted to see the result in the browser and for that had to run in the root folder which had a package.json

npm install

and after

npm start

First command worked fine but the second was giving the following error

> HOST=0.0.0.0 PORT=8000 ./node_modules/.bin/react-scripts start
'HOST' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ...: `HOST=0.0.0.0 PORT=8000 ./node_modules/.bin/react-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ... start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:

The package.json has the following

"scripts": {
  "start": "HOST=0.0.0.0 PORT=8000 ./node_modules/.bin/react-scripts start",

Tested using Git Bash, CMD and PowerShell and kept on getting the same error, as you can see in the following images

Git Bash

Git Bash HOST is not recognized as an internal or external command

CMD CMD HOST is not recognized as an internal or external command

PowerShell PowerShell HOST is not recognized as an internal or external command

like image 873
Tiago Martins Peres Avatar asked Dec 23 '22 19:12

Tiago Martins Peres


1 Answers

Method 1

If I run (without using the npm wrapper script)

HOST=0.0.0.0 PORT=8000 ./node_modules/.bin/react-scripts start

Starting the development server...

it works fine. As Quentin says,

Must be something to do with how npm shells out then

To fix it, I've gone to package.json and changed the "start" script to

"start": "./node_modules/.bin/react-scripts start",

Then npm start works fine.


Method 2

Use the cross-env package.

For that install it using the following command

npm i cross-env

then go to package.json and change it to

"start": "cross-env ./node_modules/.bin/react-scripts start",

And then running npm start will also work fine:

cross-env npm start

like image 73
Tiago Martins Peres Avatar answered May 12 '23 13:05

Tiago Martins Peres