Skip to content

How to fix ‘React-scripts: Command not found’ error?

React is one of the most popular web development frameworks for a good reason. The framework lets you build single-page web apps blazingly fast and is used by some of the biggest companies around the world.

However, as good and popular as it is, it isn’t perfect and random bugs and errors pop up. In this article, we’re looking at the “React-scripts: command not found” error and giving you five solutions to solve the problem.

Also read: React vs Next.js: 3 talking points

Install React-scripts

One of the first things you should do if you can’t fetch a package is to check if you’ve installed the dependency in the first place. You can install React-scripts by opening a terminal inside your React project’s home directory and entering the following command.

npm i react-scripts
How to fix 'React-scripts: Command not found' error?

Let NPM run and install the dependency before relaunching your project, and the error should go away. If you prefer yarn to npm, feel free to replace the package manager’s name, the command remains the same.

Check for incorrect naming practices

Another possible cause your React project isn’t working as it should is because you’ve named the root folder incorrectly. Remember that you can’t have spaces or colons (:) in the root folder name or any folder name. While your project might work with spaces or colons in folder names, it’s not the recommended practice as it can introduce uncalled for bugs in the project during further development.

Reinstall all dependencies

If installing React-scripts didn’t do the trick, try installing additional core dependencies alongside the package to ensure you have all the basics you need for the project to function. Navigate to your project’s root directory inside a terminal and enter the following command. 

npm install --save react react-dom react-scripts

Now restart the project, and React should be able to fetch all the files it needs. 

Delete the node_modules folder

The node_modules folder inside your React project’s directory stores all the dependencies you need or install to get the project going. However, if you’ve just copied a repository from GitHub or messed up something with your project, chances are the same folder can also cause problems.

Luckily, solving this problem is rather easy. All you have to do is open a terminal and type the following commands one at a time. 

rm -rf node_modules
npm install
npm start
How to fix 'React-scripts: Command not found' error?

From the three commands mentioned above, first, delete the node_modules folder and then use NPM to fetch all the required dependencies again before starting the project. This is equivalent to reinstalling a program you’re facing problems with to freshen out files and get rid of any corrupted ones that might be causing problems. 

Include React-scripts in your package

Another potential reason React-scripts might not be working is because of an incorrect reference in your packages.json file. The file keeps track of all the dependencies you’re using in your project, but you can face problems if a reference is incorrect. 

All you have to do is find this line in the file

"start": "react-scripts start"
How to fix 'React-scripts: Command not found' error?

And replace this line with the line below

"start": "NODE_ENV=production node_modules/react-scripts/bin/react-scripts.js start"

Now restart your project, and React should be able to fetch the dependency. 

Also read: Flutter vs React Native vs Ionic vs Xamarin

Hello There!

If you like what you read, please support our publication by sharing it with your friends, family and colleagues. We're an ad-supported publication. So, if you're running an Adblocker, we humbly request you to whitelist us.