[Solved] How to solve sh: react-scripts: command not found after running npm start
Problem:
I am trying to run a react application that I cloned from Github. But when I try to run the application using this command:
npm install -g create-react-app
npm install --save react react-dom
npm start
It throws errors. This is the error I am getting after running those commands:
sh: react-scripts: command not found after running npm start
How can I solve this error?
So in this article, we are going to learn how to solve sh: react-scripts: command not found after running npm start - this error.
Solution 1:
This type of error normally happens because it is missing node_modules. Check that if you have the node_modules folder in your root folder. If not run these commands in your terminal:
If you are using npm:
npm install
npm start
If you are using yarn:
yarn
yarn start
If the node_modules folder exists in your root folder you can remove it by using this command:
rm -rf node_modules
now run npm install or yarn
Solution 2:
Now check if your folder has yarn.lock file which means it was created using yarn. Usually, you can run the application using npm whether it was created by npm or yarn. But sometimes it gives you errors. So if you have yarn.lock use the following code:
yarn
yarn start
Solution 3:
You should not install react-scripts globally. This also throws errors. So install react-scripts only for your project.
npm install --save react react-dom react-scripts
Solution 4:
You can set your NODE_ENV to production manually if all the above solution does not work for you. So, in the package.json file
Change this:
"start": "react-scripts start"
Into this:
"start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start"
Hope this solves the problem you are having. If you need any more help you can comment below.