Maybe everyone is very familiar with Reactjs. It is a UI library developed by Facebook to support building website interfaces. Besides the advantages of Reactjs, in the process of using it, users will also encounter many problems that have not been found to be handled. One of those errors is “sh: react-scripts: command not found”. Our article below will summarize the fastest solutions for you.
When does it occur?
When this error occurs you will be very easy to recognize. Suppose you are needing to install the following 2 packages:
npm install -g create-react-app npm install --save react react-dom
And, below is the display of the error after the user runs the command line “
sh: react-scripts: command not found
What causes error?
- 1. One of the most common causes of “react-scripts: command not found” error is that node_modules still exists in your directory.
- 2. In addition, it is possible that the version you are using is not stable, so another version needs to be installed.
- 3. Another possible scenario is that there is a special symbol in your path such as “&”, which can also lead to the above error.
3 ways to deal with error “sh: react-scripts: command not found”
There are many ways to handle the above error. However, you should read the content of each method carefully to find the most suitable option for you to be able to solve the problem quickly. Here are 3 ways to deal with the error, please refer to it!
1: Using react-scripts
Before running the program with
npm start , you need to set up react-scripts by using the following command:
npm i react-scripts
2: Remove node_modules
This way is very simple. Firstly, you need to remove the node_modules. There are two ways to implement it. 1st way is to run below command line, 2nd way is you will remove it in the node_modules folder.
rm -rf node_modules
Next, to make sure to download all deps you need to install this command line:
and here is the last step, use this command line to start your project and that’s your problem solved.
3: Related to package.json file
For this way, after accessing the package.json file, please change this command line:
"start": "react-scripts start"
by this line:
"start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start"
In this article, we went together to learn about the “sh: react-scripts: command not found” error and how to handle it. This is a very basic knowledge of it, but also very important in the process of working with ReactJS later. Hope the article will help you.