React-scripts: command not found Error

React-scripts: command not found Error

  • Blog
  • 3 mins read

The "react-scripts: command not found" error occurs when the react-scripts package is not installed in your project or is not listed in the dependencies object in your package.json file. To fix this error, you can try the following steps:

Resolving Error: react-scripts: command not found

  1. In your terminal, navigate to your project's root directory (where your package.json file is located) and run the following command to install all of the dependencies listed in your package.json file:
# with NPM
npm install

# with Yarn
yarn
  1. If the installation command fails, try running it again with the --force flag:
npm install --force
  1. If the error persists, try specifically installing the react-scripts package by running the following command:
# with NPM
npm install react-scripts

# with Yarn
yarn add react-scripts
  1. If the installation still fails, try deleting your node_modules and package-lock.json files, cleaning the npm cache, and then running npm install again:
# delete node_modules and package-lock.json (macOS/Linux)
rm -rf node_modules
rm -f package-lock.json

# delete node_modules and package-lock.json (Windows)
rd /s /q "node_modules"
del package-lock.json

# clean npm cache
npm cache clean --force

# install packages
npm install
  1. Make sure the path to your project does not contain any special characters such as spaces or hashes. For example, instead of "my react app" or "app#3", use hyphens as separators, e.g. "my-react-app".
  2. Check your package.json file and ensure that the react-scripts package is listed in the dependencies object, not the devDependencies object or globally installed. If it's not listed in the dependencies object, add it manually and then run npm install.
"dependencies": {
  "react-scripts": "5.0.0",
  "react": "^18.0.0",
  "react-dom": "^18.0.0"
}

If the error persists after trying these steps, you may want to try installing the latest version of the react-scripts package by running the following command:

# with NPM
npm install react-scripts@latest react@latest react-dom@latest

# with Yarn
yarn add react-scripts@latest react@latest react-dom@latest

Final Words

In conclusion, the "react-scripts: command not found" error can be fixed by installing the react-scripts package in your project. To do this, you can try running the npm install or yarn command in your terminal, specifically installing the react-scripts package with npm install react-scripts or yarn add react-scripts, deleting the node_modules and package-lock.json files and reinstalling your dependencies, or installing the latest version of the react-scripts package. If the error persists, make sure the path to your project does not contain any special characters and that the react-scripts package is listed in the dependencies object in your package.json file.

Related: