react-scripts: command not found error [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 6, 2024
2 min

banner

# react-scripts: command not found error [Solved]

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

run npm install command

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

run npm install with force flag

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

# Install the react-scripts package

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

# Delete your node_modules and reinstall your dependencies

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
# ๐Ÿ‘‡๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json # ๐Ÿ‘‡๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json # ๐Ÿ‘‡๏ธ clean your npm cache npm cache clean --force # ๐Ÿ‘‡๏ธ install packages npm install

# Make sure the path to your projects doesn't contain special characters

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 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.

# Verify react-scripts is in your dependencies object

If you still get the 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

install react packages latest version

If the error persists, you might not have set up Node.js in your PATH environment variable correctly on macOS or Linux.

I've written a step-by-step guide on how to set up Node in your PATH on macOS or Linux.

Click on the link, follow the instructions and rerun the react-scripts installation command after configuring your PATH.

If you get the react-scripts is not recognized as an internal or external command error on Windows, follow the instructions in this article on how to set up your PATH.

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.

Copyright ยฉ 2024 Borislav Hadzhiev