'react-scripts' is not recognized as an internal or external command

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
3 min

banner

# 'react-scripts' is not recognized as an internal or external command

To solve the error "react-scripts is not recognized as an internal or external command, operable program or batch file", open your terminal in your project's root directory and install the react-scripts package by running npm install react-scripts and clear your npm cache if necessary.

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

shell
# ๐Ÿ‘‡๏ธ With npm npm install react-scripts # ---------------------------------------------- # ๐Ÿ‘‡๏ธ With yarn yarn add react-scripts

install react scripts using npm

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

If you are on Windows, run the following commands in CMD.

cmd
# ๐Ÿ‘‡๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐Ÿ‘‡๏ธ clean the npm cache npm cache clean --force # ๐Ÿ‘‡๏ธ install packages npm install

If you are on macOS or Linux, run the following commands in bash or zsh.

shell
# ๐Ÿ‘‡๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐Ÿ‘‡๏ธ clean the npm cache npm cache clean --force # ๐Ÿ‘‡๏ธ install packages npm install

# Restart your code editor and development server

Make sure to restart your IDE and dev server if the error persists.

VSCode often glitches and a reboot solves the issue sometimes.

# Run the npm audit fix command

If the error persists, open your terminal in your project's root directory and run the npm audit fix command:

shell
npm audit fix

issue npm audit fix command

The npm audit fix command looks for vulnerabilities and applies remediations to the package tree.

If you get an error while running the command, add the --force flag at the end:

shell
npm audit fix --force

issue npm audit fix with force flag

You can also try running the command with the --legacy-peer-deps option.

shell
npm audit fix --legacy-peer-deps

# Install the latest version of react-scripts

If the error is not resolved, try installing the latest version of react-scripts.

shell
# ๐Ÿ‘‡๏ธ With npm npm install react-scripts@latest # ---------------------------------------------- # ๐Ÿ‘‡๏ธ With yarn yarn add react-scripts@latest

install react scripts latest version

# Clean the cache and rebuild

Another thing you can try is to clean the npm cache and run the npm rebuild command.

shell
npm cache clean --force npm rebuild npm install

The npm rebuild command is similar to npm install and is most often used after upgrading your Node.js version.

# Verify react-scripts is in your dependencies object

If the error persists, open your package.json file and make sure it contains the react-scripts package in the dependencies object.

package.json
{ // ... rest "dependencies": { "react-scripts": "^5.0.0" } }

The react-scripts module 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 line and re-run npm install.

shell
npm install

Or install the latest version of the package:

shell
npm install react-scripts@latest

If the error persists, you likely haven't set up Node.js in your system's PATH environment variable on Windows.

I've written a detailed guide on how to set up Node.js correctly on Windows.

Click on the link and follow the step-by-step instructions.

After setting up Node.js in your PATH, restart your terminal and issue the react-scripts installation command.

shell
npm install react-scripts@latest

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

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