Solve - react-scripts: command not found error in React.js

avatar

Borislav Hadzhiev

Last updated: Apr 16, 2022

banner

Photo from Unsplash

Solve - react-scripts: command not found error in React.js #

Run the npm install react-scripts command to solve the "react-scripts: command not found" error. If necessary delete your node_modules directory and your package-lock.json file, reinstall your dependencies and restart your development server.

react scripts command not found

Open your terminal in your project's root directory (where your package.json file is) and run the following command:

shell
# 👇️ with NPM npm install # -------------------- # 👇️ with yarn yarn

The command will install all of the dependencies that are present in your package.json file.

If the installation command fails, try to re-run it with the --force flag.

shell
npm install --force
Try to re-run the npm start command after the dependencies have been installed.

If the error is not resolved, try to specifically install the react-scripts package.

shell
# 👇️ with NPM npm install react-scripts # -------------------- # 👇️ with yarn yarn add react-scripts

If the installation command fails, re-run it with the --force flag.

shell
npm install react-scripts --force

If the error is not resolved, try to delete your node_modules and package-lock.json (not package.json) files, re-run npm install and restart your dev server.

shell
# 👇️ delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # 👇️ clean npm cache npm cache clean --force npm install
If that doesn't help, make sure the path to your project doesn't contain any special characters. For example, if your project's directory or the path contains spaces, the "react-scripts: command not found" error occurs.

Make sure the directory is not named something like my react app (contains spaces) or app#3 (contains a hash). Instead, use hyphens as separators, e.g. my-react-app.

If you're still getting the "react-scripts: command not found" error, open your package.json file and make sure it contains the react-scripts package in the dependencies object.

package.json
{ "dependencies": { "react-scripts": "5.0.0", "react": "^18.0.0", "react-dom": "^18.0.0" } }

The react-scripts package should NOT be globally installed or be in your project's devDependencies, it should be in the dependencies object in your package.json file.

You can try to manually add the lines and re-run npm install.

shell
npm install

Or install the latest version of the package:

shell
# 👇️ with NPM npm install react-scripts@latest react@latest react-dom@latest # -------------------- # 👇️ with YARN yarn add react-scripts@latest react@latest react-dom@latest
I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.