Home > Mobile >  facing issue to start react application npm start error
facing issue to start react application npm start error

Time:09-11

when I issue below command to start react app facing this error, can anyone help. npm start

[email protected] start env-cmd -f .env.dev craco start

'env-cmd' is not recognized as an internal or external command, operable program or batch file.

CodePudding user response:

Did you install cross-env with npm? Try running

npm install

This should work.

CodePudding user response:

its really hard to tell without taking a look at your package.json file. but i see that you're using env-cmd package which provides custom run and build commands and lets you have multiple environment declarations. here is an example of what you can do with it in your package.json (this example is a nextjs example)

"scripts": {

    "dev": "env-cmd -f env/.env.local next dev",

    "build:pre": "env-cmd -f env/.env.pre next build",

    "start:pre": "env-cmd -f env/.env.pre next start",

    "build:stg": "env-cmd -f env/.env.stg next build",

    "start:stg": "env-cmd -f env/.env.stg next start",

    "build:rc": "env-cmd -f env/.env.rc next build",

    "start:rc": "env-cmd -f env/.env.rc next start",

    "build:prod": "env-cmd -f env/.env.prod next build",

    "start:prod": "env-cmd -f env/.env.prod next start"

  },

as you can see i created a build and run command for each environment and i also provided a .env.ENVNAME file for my config. the env/,env.ENVNAME is the path of my .env files. the env folder is in the root of the project. here is how to run and build the app with env-cmd for above scripts:

npm run build:Env_name for example for building my stg env: npm run build:stg

or for starting the app npm run start:Env_name for example: npm run start:stg

in your local you can use npm run dev to run the application and npm run build to build it.

  • Related